The determined Real Programmer can write FORTRAN programs in any language.
-- Ed Post, Real Programmers Don't Use PASCAL.
I just read through a friend's shell script. He doesn't program in the shell much, but he's a superb C programmer, so his script has loops that look like this:
file[0]=foofile[1]=barfile[2]=mumblesuffix[0]=.csuffix[1]=.hsuffix[2]=.txtnfiles=${#file[@]}nsuffixes=${#suffix[@]}
i=0while [ $i -lt $nfiles ]doj=0while [ $j -lt $nsuffixes ]doprocess ${file[$i]}${suffix[$j]}(( j = j + 1 ))done(( i = i + 1 ))done
Yep. That'll work. But this will, too.
for filename in {foo,bar,mumble}.{c,h,txt}do
process $filenamedone
Bash sees filenames as strings, and most shell commands accept space-separated lists of filenames. The shell handles anything that expands to a list of filenames, like globs or brace expansions, with real ease.
Use the Shell, Luke.
No comments:
Post a Comment