Search code examples
bashzsh

Does the order of command line flags matter?


I am testing Hugo static blog generator which comes with themes and example sites within them.

In order to easily use exampleSite, I just copy the content it's content to Hugo project root. While I did this, I noticed that where, I put the -flag args seems to be important.

Is this is a normal bash behavior or something introduced by zsh?

This command didn't work

cp themes/hugo-theme-bootstrap4-blog/exampleSite/* . -R

This command worked!

cp -R themes/hugo-theme-bootstrap4-blog/exampleSite/* .

Solution

  • cp is its own command, provided by your OS vendor. Neither bash nor zsh controls the behavior of cp.

    The POSIX standard only requires cp to accept options before arguments. This is given in POSIX utility syntax guidelines, entry #9:

    1. All options should precede operands on the command line.

    GNU tools go beyond this requirement, accepting options after arguments unless -- is given prior (as described in guideline #10).