this post was submitted on 03 May 2024
14 points (64.6% liked)
Linux
48078 readers
844 users here now
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I disagree. The vast majority of the time when writing shell scripts, I quote variables, because that's almost always what I want. Splitting is basically only useful if you have a list of arguments, and you know for sure there are no spaces in any of the arguments (so no filenames).
(The workarounds in pure POSIX shell are btw super annoying if you want to pass a list arguments that may have spaces in them: You can abuse the special
"$@"
variable. Or you could probably also construct something with xargs.)Every single command, option and argument in the shell is split by spaces, regardless of what it contains. That is clearly the more common case. I am not talking about splitting when the space comes out of a variable but in general, as part of the syntax.
I am well aware of how quoting works to avoid accidental splitting and it is an absolute non-issue in practice once you get used to quoting things, about as annoying as the fact that you have to quote strings in every other programming language, i.e. not at all.
Ah that's your point. Yeah I agree that splitting literal
a b c
is convenient. It is surprising to many (like here) that this happens after variable substitution, and that's not very convenient since you almost never want that. You could define this to happen the other way around, but then you'd obviously have to invent a new syntax for explicit splitting, which would be its own kind of annoying.Edit: YSH (oil) does that btw. See here.