简体   繁体   中英

macos command line params not working at the end

On linux systems when you type a command in a shell like rm * -rf , the order of the * and the -rf doesn't matter. My shell interpret it the same way. Now, on my Mac when I type rm -rf * everything works fine, but if I do rm * -rf an error shows up rm: -rf: No such file or directory

I tried that on a macOS and a linux both with fish and bash shells. Same problems.

Does anyone have any idea why the command interpreter on macOS thinks that -rf at the end of the command is not interpreted as parameters of the command ?

It's not about the shell, it's about the commands. The parsing of command line arguments is not a feature and responsibility of the shell, but of the actual commands. In both systems the shell faithfully passes the command line arguments in whatever order they were specified, and then it's up to the implementation of the commands to parse them as they see fit.

In linux, the core utilities are typically of the GNU implementation, while on osx, the core utilities are typically of the BSD implementation.

The man page of the commands should tell you which implementation it is.

For example the last line of man rm in Linux is something like this:

 GNU coreutils 8.21 March 2016 RM(1) 

On osx:

 BSD January 28, 1999 BSD 

Order of the arguments in any shell has historically been relevant in unix.

rm incidentally even has an option -- to stop parsing options (to be able to remove files that start with "-" eg)

See rm(1) and getopt(3) man pages

if the shell doesn't respect order of the arguments it is given just what would the result be of this sequence:

$ touch a b 
$ mv a b 

what file would remain ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM