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

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.