Home » » Shell Scripting Tutorial For Beginners Xviii - For Loop

Shell Scripting Tutorial For Beginners Xviii - For Loop



Basic Syntax:



for VARIABLE inward 1 two iii iv five .. N do  command1  command2  commandN done #OR-----------------------------------------------  for VARIABLE inward file1 file2 file3 do  command1 on $VARIABLE  command2  commandN done #OR-----------------------------------------------  for OUTPUT inward $(Linux-Or-Unix-Command-Here) do  command1 on $OUTPUT  command2 on $OUTPUT  commandN done #OR----------------------------------------------- for (( EXP1; EXP2; EXP3 )) do  command1  command2  command3 done 




Example:



#!/bin/bash # for loops #Example 1 ------------------------ for i inward 1 two iii iv 5 do    echo $i done  #Example two ------------------------ for i inward {0..10} do    echo $i done  #Example iii ------------------------ for i inward {0..10..2} do    echo $i done  #Example iv ------------------------ echo ${BASH_VERSION} for (( i=0; i<5; i++ )) do    echo $i done 

0 comments:

Post a Comment

Search

Blog Archive