Unix Basics Part 7 | Shell script - loop | while for until for loop | #unix #unixtutorial
#loop #loopinunix #while #for #until #for #learning #programming
---------------------------
While loop e.g.:
./test_while.sh 19
#!/bin/sh
multiplier=1
start_value=$1
echo "Table of $start_value"
while [ $multiplier -le 10 ]
do
table_of_value=`expr $start_value \* $multiplier`
echo "$start_value X $multiplier is"
multiplier=`expr $multiplier + 1`
echo $table_of_value
done
--------------------------
for loop e.g.:
./test_for_loop.sh 19
#!/bin/sh
start_value=$1
for multiplier in 1 2 3 4 5 6 7 8 9 10
do
table_of_value=`expr $start_value \* $multiplier`
echo "$start_value X $multiplier is"
echo $table_of_value
done
----------------------
until loop e.g.:
./test_until.sh 19
#!/bin/sh
#Auther technocoders
start_value=$1
multiplier=1
until [ $multiplier -gt 10 ]
do
table_of_value=`expr $start_value \* $multiplier`
echo "$start_value X $multiplier is"
multiplier=`expr $multiplier + 1`
echo $table_of_value
done
--------------------------
select loop e.g.:
./test_select_loop.sh 19
#!/bin/bash
#Auther technocoders
start_value=$1
select multiplier in 21 22 28 30 -1
do
table_of_value=`expr $start_value \* $multiplier`
echo "$start_value X $multiplier is"
echo $table_of_value
if [ $multiplier -eq -1 ]
then
break;
fi
done
--------------------------
Негізгі бет Unix Basics Part 8 | Shell script - loop | while | for | until | select loop |
Пікірлер