You are not logged in.
Pages: 1
How can I write non-numerical for loop in bash?
for example.. I want something like this....
for cName in ('bzip2' 'bunzip2' 'gzip' 'gunzip')
do
time $cName -kf $filename
done
instead of writing this...
time bzip2 -kf $filename
time bunzip2 -kf $filename
time gzip -kf $filename
time gunzip -kf $filename
Can this be done? (I have larger set of tools I want to run that have same flags and stuff like that in the end... not just 4)
Last edited by kdar (2012-05-10 02:03:12)
Offline
Thanks.
Is it better to use double quotes?
Last edited by kdar (2012-05-10 02:10:49)
Offline
Thanks.
Is it better to use double quotes?
I think Falconindy meant to put double quotes around the variables when you use them. Think about what would happen if $filename had a space in it. Try running these two examples:
filename="foo bar"
for i in $filename; do
echo $i
done
filename="foo bar"
for i in "$filename"; do
echo $i
done
Offline
Pages: 1