Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by PhilipRoman on Saturday January 06, 2024 @03:40AM
(#38889699)
The shell command is very readable.
a && b && c is a common idiom for "stop if any step fails". In the shell language && and || are more like control flow concepts, rather than binary operators.
And a && b || c is a universal "ternary operator" (with one minor deviation) idiom across many languages, not just the shell
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by pavlov on Saturday January 06, 2024 @02:19AM
(#38889250)
Shell scripting sucks, but that’s hardly news.
If I really have to touch a bash script, I just assume nothing works like I might expect from proper programming languages despite any surface similarity, and google every construct with sweat drops dripping down my face. ChatGPT has made the process somewhat more tolerable.
[ -e "${target}" ] && echo "Getting information about ${target}" && stat "${target}" || echo "Failed to stat file."
EDIT: What about the || die("...") pattern in Perl?
Or the fact that the glyphs in || are visually lower than the glyphs in &&?
Or that "and" comes before "or" in the expression "and/or"?