this post was submitted on 03 May 2024
13 points (63.8% liked)

Linux

48328 readers
659 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

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I know that there are ten different alternatives. Why don't we simply improve the basic stuff?

you are viewing a single comment's thread
view the rest of the comments
[–] OpenStars@discuss.online 56 points 6 months ago (11 children)

It has nothing to do with bash specifically - other shells like sh, csh, tcsh, zsh, etc. are the same. Whitespace in UNIX is just that way by design. And it's been a long while since I used a Windows CLI but they were that way too - plus added all that weirdness about ~1 at the ends of filenames, and Mac OSX also. So not even just UNIX, but it's how the CLIs tend to work, where whitespace acts as the "delimiter" between arguments sent to a program.

program_name arg1 arg2 arg3 arg4

So if you use whitespace like "cp file 1 file 2", the CLI sends arg1="file", arg2="1", arg3="file", arg4="2", rather than arg1="file 1" and arg2="file 2". These are just the foundational rules of how CLIs work - a computer can't read your mind, and this is how you precisely tell it what you want, within this highly rigid framework to avoid misunderstandings.

The alternative is to use a GUI, so like see file, drag file, and ofc that has its own set of tradeoffs good and bad.

[–] GenderNeutralBro@lemmy.sdf.org 5 points 6 months ago (8 children)

other shells like sh, csh, tcsh, zsh, etc. are the same

Zsh has some important differences in how it handles whitespace and quoting, which affects OP's exact example.

Consider this:

touch a b c 'd e f' 'g h i'
for f in *; do ls -la $f; done

In zsh, this works. In bash, it will give you six errors saying d, e, f, g, h, and i do not exist.

[–] bizdelnick@lemmy.ml 5 points 6 months ago (1 children)
touch a b c 'd e f' 'g h i'
for f in *; do ls -la "$f"; done

fxd

[–] GenderNeutralBro@lemmy.sdf.org 6 points 6 months ago (1 children)

That will work in either zsh or bash, yes. It's a good habit to use quotes, but I am pointing out that quoting and expansion behavior is not the same across all shells.

[–] bizdelnick@lemmy.ml 6 points 6 months ago

It's the same across all POSIX compliant shells. zsh is not POSIX compliant.

load more comments (6 replies)
load more comments (8 replies)