1

Let's say I want to copy a directory A to B, I should execute this command cp -r A B but for some reason I forgot to give it the -r flag. Comming from Linux I usually do !! -r but this is not a valid option in Mac.

~/tmp ❯ echo $SHELL
/bin/zsh
~/tmp ❯ cp A B
cp: A is a directory (not copied).
~/tmp ❯ !! -r
~/tmp ❯ cp A B -r
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory

Is this the difference between BSD and GNU? Is it possible to give options at the end of the command on Mac? I'm using Zsh in both Linux and MacOS

8
  • AFAIK the !! is a ZSH feature. So are you using ZSH on Linux but Bash on macOS? You can find out simply via echo $SHELL?
    – DarkDust
    Sep 9 at 16:03
  • This is a feature of the shell - which one are you using in Linux and in macOS and what is youe environment whenyou try the !! command
    – mmmmmm
    Sep 9 at 16:12
  • !! is in bash gnu.org/software/bash/manual/html_node/… 9well at least in current bash - I can't remeber if macOS old bash has it)
    – mmmmmm
    Sep 9 at 16:13
  • bash does. And it's a configurable option in ksh. Dunno if it's on by default in zsh or if it's something you have to enable. But options after arguments are not valid in BSD. Sep 9 at 20:47
  • I'm using Zsh in both Mac and Linux via Alacritty
    – Tai Nguyen
    Sep 10 at 3:42
1

The default commands on macOS don‘t accept options at the end, so !! -r won‘t work. You can install the GNU versions via Homebrew.

PS: You could also type ^cp^cp -r^, but that's rather cumbersome.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .