bash looping
1/30/2010 09:52:00 AM
Posted by johnhomer
Basic Loop
#!/bin/bash for i in 1 2 3 4 5 do echo "Number $i" done
Output:
1 2 3 4 5
Using seq
#!/bin/bash for i in $(seq 1 2 20) do echo "Number $i" done
Output:
1 3 5 7 9 11 13 15 17 19
Using the C-style loop:
#!/bin/bash for (( c=1; c<=5; c++ )) do echo "Number $c" done
Simple isn't it?
If you want an infinite loop:
#!/bin/bash for (( ; ; )) do echo "infinite loops [ hit CTRL+C to stop]" done
If you are working with files:
#!/bin/bash for file in /etc/* do echo $file done
Those are just the basic. There are tons of tutorial online. I will leave the rest of the topics to you.
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)
Post a Comment