|
|
|
|
|
by alphapapa
4119 days ago
|
|
Always use double-brackets [[ ]] if you're writing Bash (not sh) scripts. They are better. Double-parentheses (( )) are only for arithmetic, e.g. "((count++))" or "echo $((1+1))" The dollar sign precedes parentheses--i.e. $()--when you're substituting the output of a command, e.g. "echo Today is $(date)". It's easy to remember, because it's just like using the dollar sign for substituting the value of a variable, i.e. "date=$(date); echo $date". You might want to look into the fish shell. Its scripting is much less idiosyncratic. You don't have to quote any variables, arrays, or command substitutions. e.g.: set foods apple banana 'cucumber casserole'
for f in $foods
echo $f
end
prints: apple
banana
cucumber casserole
...not: apple
banana
cucumber
casserole
...as would be the case if you forgot to quote "$foods" and "$f" in Bash. |
|