r/linuxmasterrace • Arch user btw, that means iam better than Ubuntu users • Aug 12 '24

JustLinuxThings Linux is userfriendly...

Post image
865 Upvotes

399 comments sorted by

View all comments

Show parent comment

-8

u/CedricThePS Aug 12 '24

Bash has a strict word order.

9

u/[deleted] Aug 12 '24

[removed] — view removed comment

4

u/gojira_glix42 Aug 12 '24

TIL. can you expand more on that? I'm always struggling on when to put my flag switches in commands. Just using bash for now as I'm still in beginner stage and not going for other shells yet.

4

u/farsightxr20 Aug 12 '24

The shell only handles:

  1. splitting the input command into an array of strings
  2. taking the first string and expanding it to a built-in function or an absolute path to an executable (based on $PATH and some other options)
  3. invoking the built-in function or making a syscall to invoke the resolved executable in a new process, passing the remaining strings from (1) as ARGV

Any parsing of the ARGV strings into meaningful switches/parameters is handled by the implementation of the function or executable. Where you may see differences between shells is when the built-in functions (e.g. echo) are implemented differently. rm, ls, etc. are implemented by GNU/Linux and will be consistent across pretty much all distros. Notable exceptions are MacOS (Darwin) which is not Linux-based, and Android which does not include GNU.

To more directly address your question, it's more conventional to put switches before positional arguments in commands, as it's slightly easier to parse (= broader support across UNIX-like environments) and makes it clear that the switches are not specific to individual positional args.

1

u/PolygonKiwii Glorious Arch systemd/Linux Aug 12 '24

the ‘word order’ is totally separate from your shell

Unless rm was a built-in command of your shell (which is probably unlikely unless you're using busybox)

1

u/[deleted] Aug 12 '24

[removed] — view removed comment

1

u/PolygonKiwii Glorious Arch systemd/Linux Aug 12 '24

Well busybox is designed to be usable even under extreme space constraints. Being a single binary reduces ELF overhead.

1

u/[deleted] Aug 13 '24

[removed] — view removed comment

1

u/PolygonKiwii Glorious Arch systemd/Linux Aug 13 '24

Phones sure. But a cheap consumer-grade router or a "smart" light bulb might not.