Automation/scripting is when CLIs really come into their own as otherwise you end up becoming a GUI click monkey. The best is when there's both a GUI and CLI (as long as they work the same way).
That's what the man page is supposed to be (and most do contain example) and why GNU wanted to split it into info (tutorials and exhausting documentation) and man (reference and examples).
I usually end up just doing a quick web search for the command if it's not one that I'm familiar with (i.e. where I have read the man page).
An extreme example of my issue would be trying to find BASH examples of how to process a list of files - the man page on BASH is fairly lengthy.
Meanwhile, Greg's wiki provides this example of processing mp3 files:
while IFS= LC_ALL=C read -r -d '' file; do
some command "$file"
done < <(find . -type f -name '*.mp3' -print0) find . -type f -name '*.mp3' -exec some command "'{}'" ';'
That sounds just unnecessary and bug prune. Unless you target some odd platform where find doesn't support '-exec', but it is even in POSIX. I think due to your use of process substitution, your code has a higher chance of being unportable, so why do you want to complicate your code?Stuff like that is why I personally prefer the man pages to random websites.
Honestly for something as complex as a shell (which describes both a language, an editor, and an implementation) the man page is surprisingly short. (6418 lines for me) I have just found the section on process substitution in <1min, without even using the search, just by reading. I looked it up, because I didn't knew the name of that syntax, so I needed to actually look for what I wanted and I do not use the man page of bash often.
Don't get me wrong, the BASH man page is great, it's just that I prefer to work with examples.
For reference, here's the Greg's Wiki explanation: https://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_....
touch "$(echo -en 'a\nb')"
find . -type f -name '*.mp3' -exec bash -c "echo '{}'; ls '{}'" ';'
works just fine, but maybe it doesn't work everywhere.If you don't like how the multiple commands look like, you can always write it like this:
find . -type f -name '*.mp3' -exec bash -c "
echo '{}'
ls '{}'
" ';'(Very minor nitpick, it should be 'a\nb.mp3' to be included, but that does work fine)
Incidentally, ShellCheck isn't happy with that although I don't follow their reasoning:
find . -type f -name '*.mp3' -exec bash -c "
^-- SC2156 (warning): Injecting filenames is fragile and insecure. Use parameters.
https://www.shellcheck.net/wiki/SC2156I think it is sound. Imagine what happens when the filename contains:
' && shutdown now && '.mp3Anyhow here's an example of how I would use the while loop and process substitution in a BASH script:
declare -i file_count=0
while IFS= LC_ALL=C read -r -d '' file; do
file_count+=1
printf "file: %s\n" "${file}"
done < <(find . -type f -name '*.mp3' -print0)
printf "Processed %d files\n" "${file_count}"
I think that'd be tricky to do using just a find/-exec command. find . -type f -name '*.mp3' | wc -l
Honestly I don't really view the shell / filesystem interface as a security boundary. I use the shell mainly for (automation of) interactive use, so any screwup due to e.g. quoting issues is my own fault, maybe even of using stupid filenames. Shell is a great language to connect streams of different programs into each other, not so much for doing any work. If I do that, I would reach for C.You're right about just using "wc -l", but I was just trying to demonstrate how you can set variables. A real use would be doing more than just counting files as your example would likely be quicker (assuming that calling an external programme is quicker than running a naive loop in BASH).
I am guilty of using BASH for stuff that most people would use a different language for - I just find that for system admin work that BASH is just at the right level of abstraction for me and is ubiquitous.
On face value, I find this suggestion hilarious. People are having sandboxing issues left, right and center with AI agents and MCPs, so clearly there would be enormous problems with giving an LLM full unscoped terminal access. Remember the guy who had his hard drive wiped?
Do you just mean that the ABIs are inconsistent and you want a more unified way to specify what you want (but the user still more-or-less spells out what command will be invoked)? I have some sympathy for that concern, yes.
This always annoys me because you're really handicapping yourself by ignoring the CLI on any OS. Sure I use it more heavily on GNU/Linux than I did on Windows as a kid, but that's because it's so good. If I'm ever in front of a Windows machine now I still like to have a terminal handy (and it's even better/more-familiar on macOS, of course), and I've learned things like "type is like cat", "robocopy is like rsync", "tasklist is kinda like ps and taskkill like kill/pkill" which help me to do things better on Windows than when I used it fulltime. I'm glad Microsoft invested more in the CLI with Windows Terminal, OpenSSH in the default install, winget, PowerShell, etc. I think it's better for everyone. I fear the CLI hate is spreading anti-intellectualism. Some people seem annoyed when they even have to use their keyboard instead of their mouse for something.