Linux Shell Scripting Tutorial
Introduction Tools required for shell scripting First shell script Interacting with user Operators Special characters in BASH scripting Variables in Linux BASH scripting Arrays Integer operations floating point operations String manipulation in shell scripting Parameter substitution Command Substitution Conditional statements Looping statements Passing parameters exit status of the script Functions Sourcing filesLooping statements in linux shell scripting
We can use below looping statements in Linux shell scripting.
while
for
while loop
while <condition>
do
statements….
done
Here is an example on while loop. Below loop will print values from 1 to 10.
count=1
while [ “$count” -le 10 ]
do
echo $count
# let “count += 1”
((count = count + 1))
done
for loop Here are some of the examples on for loop.
for i in 1 2 3 4 5
do
echo “value of i is $i”
done
for i in {1..3}
do
echo “value of i is $i”
done
for (( i=1; i<=3; i++ ))
do
echo “Value of i -> $i”
done
Below code will kill all process that match pattern – “myPattern”
for KILLPID in `ps ax | grep ‘myPattern’ | awk ‘ { print $1;}’`; do
kill -9 $KILLPID;
done
for KILLPID in `pgrep anyprocessname`; do
kill -9 $KILLPID;
done
Web development and Automation testing
solutions delivered!!