Search code examples
linuxbashmacosshellargs

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 ?


Solution

  • 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