|
|
|
|
|
by shanusmagnus
4120 days ago
|
|
I'm with you. I have written a mountain of Bash scripts to solve various one-off problems, and I'm fucked if I can ever remember the nuances from one time to the next -- when to use [], when [[]], when () or (()), when the dollar sign precedes (), etc. Every single time I have to do anything in Bash I have to re-learn Bash. I suppose I keep using it because, even with having to re-learn every single element of Bash coding every time, it's still faster for doing a bunch of filesystem stuff for me. But god, I hate it. I can't think of a computer technology I hate more. I hate it more than R, and I really hate R too, for some of the same reasons. I keep intending to learn Perl really well, which I think could absorb much of Bash, and also Awk and Sed, and then there would be only one thing I needed to know for this kind of work, and I might use it enough to remember the various weird syntactic bits from one month to the next. But I never quite get over the hump. |
|
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.:
prints: ...not: ...as would be the case if you forgot to quote "$foods" and "$f" in Bash.