Shell scripting loops - miraj/tools GitHub Wiki
Question1
How does echo * works? what is passed to echo command as arguments? one argument : *? or something else?
Question2
Why does is space needed after [ and [ [ operator? Is [ an operator or a command? Space is used to separate arguments from commands.
How does for loop works?
for name in ram shyam sam john do echo -n $name : grep $name details.txt done
Consider name, in, ram, shyam etc as arguments to the function "for"
for f in *; do echo $f; done will be expanded as: for f in file1.c file2.c file.h; do echo $f; done
Some Examples
Loop through all .cpp files in the sub folders
for f in `find . -name "*.cpp"`; do echo $f; done
Simply loop 20 times
for f in `seq 1 20`; do echo $f; done