this post was submitted on 22 Sep 2025
967 points (98.9% liked)
Programmer Humor
26551 readers
1713 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
If your code is written well, it shouldn’t matter.
They're annoying to deal with when interactively using command-line shells, especially so when pasting unquoted and unescaped file paths, doubly especially so with Bash where parameter expansion makes no goddamn sense if you know at least one other programming language
Example of how parameter expansion matters?
Generally if you are pasting file paths there is a better way to do that. Use find with exec, or xargs, or a for loop. Or, get the list in Vim and escape (quote) every line at once. Unless you have double quotes in the filename too (which is actually a crazy thing) it shouldn’t be a big deal.
Expansion matters because using parameters without quotes automatically splits words, and IIRC a quoted array parameter can still be split into its members — as opposed to Zsh, where word splitting doesn't happen unprompted and quoted array parameters are flattened into a single string.
Generally if I want to run
$HOME/random executable with spaces.exe
through Wine in a terminal I copy the path in Dolphin (CTRL+SHIFT+C, or CTRL+ALT+C idr) and paste it, within quotes if needed (the four extra key inputs are the annoying part).I find that much faster than manually typing
find "$HOME" -name "random executable with spaces.exe" -type x -exec wine "{}" \;
, or opening an editor to insert backslashes.Why on earth not just type
wine ~/random
and then hit tab to autocomplete? Or you could doAFAIK, if $file is a filename with spaces, then
some_util ${file}
will not split the filename.If the path to the dir is longer than
$HOME
, say,$HOME/Tools/modding/hd2-audio-modder/wwise/v123456789_idr_but_its_a_long_one/random file name with spaces
, it makes more sense.I'll try using the braces syntax, if it does prevent word splitting I wasn't aware of it, though it's still slightly inconvenient (3 key inputs for each brace on my kb) and I'd probably still use quotes instead if I had to use Bash and had the file path in a variable for some reason.
... though at this point I'm probably overthinking it, atm I don't recall better examples of my distaste for Bash expansion shenanigans.
Did some testing, here's what I found.
Beware, it devolves into a rant against Bash and has little to do with the original topic - I just needed to scream into the void a little.
Upon further investigation:
I get that the Bash equivalent to Zsh's
$array
is${array[@]}
, but making$array
behave like it does in Bash has no advantage whatsoever.... IS WHAT I WOULD SAY IF THAT WERE TRUE! YOU ALSO HAVE TO QUOTE
"${array[@]}"
BECAUSE WE LOVE QUOTES HERE AT BASH HQ!While this behavior doesn't make much sense to me, it also doesn't make sense for me to write that "prefix" within the quotes in the first place, right?
YES. BECAUSE SPLITTING IS NOT WHAT YOU EXPECT WHEN YOU PUT STUFF IN QUOTES.
Sorry, I'll stop.
My bad, I was thinking of zsh. And I think it’s configurable there too so may not behave that way according to your settings. But it is at least the default on Mac.
I use Zsh too, though at this point is becoming detrimental to my (already limited) Bash skills because of features like the
${^array}{1,2,3}
syntax which I use in some scripts of mine, which in turn I wouldn't dare try to translate to Bash.