Bash appreciation thread

What do you even want to return? If you want to return a string do the following:
where_to_poo () { echo 'loo'}echo "Poo in $(where_to_poo)."

Return values are for exit codes, same as with the return values of commands.

Why use bash or perl when you can use python?
1. Python runs on every operating system
2. It comes preinstalled on most operating systems
3. it has returns,
4. its easier to read,
5. it has more libraries,
6. it can be maintained and expanded easier,
7. can do most things that you would do with bash in fewer lines of written code.
Unless you are on something like a home router there is no reason not to use python for automation instead of bash unless you want to frustrate yourself

It's slow as fuck to start so can't replace scripts that get called frequently, it's not guaranteed to be present as part of either UNIX or LSB, and it's 5 megs even for a minimal install so is difficult to budget for in firmware.

which is why i said most
which is why i mentioned the bit about being on things like a home router


got me there

Where are the pipelines? Also, it's slow as shit.

Python works with Unix pipes in pretty much the same ways as any other programming language which supports them

Meaning that you have to use four statement to open, write into, read from then close the pipe instead of just doing cmd1 | cmd2.

Don't try to compare a glueing language to a scripting language, it doesn't work.

It's much more tedious than a proper shell language, but it's not quite as bad as you think.
Send bytes into command, get bytes out:
>>> import subprocess as sp>>> sp.run(['tac'], input=b'foo\nbar\n', stdout=sp.PIPE).stdoutb'bar\nfoo\n'
The same thing, but with strings:
>>> sp.run(['tac'], input='foo\nbar\n', stdout=sp.PIPE, universal_newlines=True).stdout'bar\nfoo\n'
Chain three commands (seq 10 | sort -R | head -n 1) and read the output:
>>> seq = sp.Popen(['seq', '10'], stdout=sp.PIPE)>>> shuf = sp.Popen(['sort', '-R'], stdin=seq.stdout, stdout=sp.PIPE)>>> head = sp.Popen(['head', '-n', '1'], stdin=shuf.stdout, stdout=sp.PIPE)>>> head.stdout.read()b'3\n'

But that's a big pain, honestly. Sure, emulating sh in python is better than the opposite, but python is clearly not made for this.
The concept of an extremely high-level (untyped; or typed like AWK) language to act as boilerplate between other scripts and binaries is something that must be kept. If you standardize the good parts of the modern shells (mainly arrays), you'd only have to fix the lack of consistency of the various *utils (mainly, we would need a good tabular to pass stuff around. Some RS and FS env variables, with at least a couple (\t, \n sounds nice) forbidden in filenames).

TCL