Clarity is king people
Clarity is king people
foo | awk '/bar/ {print $3}'
is more clear than import subprocess
foo = subprocess.Popen(['foo'], stdout=subprocess.PIPE)
for line in foo.stdout:
if 'bar' in line:
try:
print(line.split()[2])
except IndexError:
print('')
Sometimes shell scripts are more clear. Especially for tasks that involve running lots of external commands.``` array=( a b ) array+=(c) if [ ${#array[@]} -gt 0 ]; then rm -- "${array[@]}" fi ```
``` array = [a, b] array << c array.map { |i| `rm #{i}` } if array.length > 0 ```
There's also nobody stopping you from using text processing tools like awk and sed, or bash one liners in ruby/python either, but I think we should leave the logic and arrays for scripting languages, no?
I actually think we agree with each other, but we express it differently. I never write bash scripts, I write POSIX shell, so all the array juggling of bash is something I never deal with. As you say, by the time you need arrays, you should have switched languages already.
That said, I think there's a fairly large domain of problems - apart from install scripts - that are better solved with shell scripts, because of their clarity. Anything which relies on invokation of lots of other tools, and in particular problems that fit the pipe model (take output from this tool, extract interesting bits from it, and feed it to that tool, etc). And this I say as an otherwise almost slightly fanatical Pythonista :-)