3 ms·
I write maybe one or two ad-hoc shell scripts every day, many only for a single use. Bash isn't so bad once you get used to it. Things like Perl, Python or Ruby
by barrkel 17y ago
I write maybe one or two ad-hoc shell scripts every day, many only for a single use. Bash isn't so bad once you get used to it. Things like Perl, Python or Ruby are often less suited owing to lack of parallelism or scalability without more effort than I'm willing to spend, as I typically write the scripts in 2 or 3 minutes or so. Most of my scripts are pipes of other utilities, written in a streaming style, often with multiple forks writing to temporary files and joining with a sort at the end.
I wouldn't feel the same way if it was a different sh than bash. For example, this is easy in bash:
let total=0
let n=10
for ((i=0; i<n; ++i)); do
if (( i % 2 != 0 )); then
printf 'Odd: %.3d\n' $i
fi
let total+=i
done
echo "Total is: $total, average is $((total / n))"
Staying inside bash, you only have integer arithmetic, but that's sufficient for many problems. The major advantage is that you can easily, and more importantly, readably, compose solutions using programs written in dozens of different languages. The syntax for piping programs together in scripting languages tends to be imperative, rather than declarative like a shell script.
- jacquesm 17y agoThe placing of those semicolons inside control structures gets me every time. I just don't do enough of it to make it in to an automatism.
- KC8ZKF 17y agoYou don't need the semicolons if you prefer newlines. e.g. let total=0 let n=10 for ((i=0; i<n; ++i)) do if (( i % 2 != 0 )) then printf 'Odd: %.3d\n' $i fi let total+=i done echo "Total is: $total, average is $((total / n))"