Search code examples
bashmacoscpmacos-monterey

installing latest bash on macos 12.x


I was trying a cp command that ran fine under ubuntu 20, namely

(base) jr@Historys-MacBook-Air test % cp --backup=numbered src dest
cp: illegal option -- -

which struck me as weird, so checking the man page I saw

HISTORY
     A cp command appeared in Version 1 AT&T UNIX.
macOS 12.0                                                       February 23, 2005                                                       

and I figured the shell might be to blame - I found I was in zsh

(base) jr@Historys-MacBook-Air test % echo $0
-zsh

and when I start a terminal in bash its an old version:

(base) jr@Historys-MacBook-Air test % /bin/bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.

So I tried to brew install the latest and then chsh to it but got 'non-standard shell':

...
==> Pouring bash--5.1.16.arm64_monterey.bottle.tar.gz
🍺  /opt/homebrew/Cellar/bash/5.1.16: 157 files, 11.5MB
(base) jr@Historys-MacBook-Air test % /opt/homebrew/Cellar/bash/5.1.16/bin/bash --version
GNU bash, version 5.1.16(1)-release (aarch64-apple-darwin21.1.0)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

(base) jr@Historys-MacBook-Air test % chsh -s /opt/homebrew/Cellar/bash/5.1.16/bin/bash
Changing shell for jr.
Password for jr:
chsh: /opt/homebrew/Cellar/bash/5.1.16/bin/bash: non-standard shell

Can anyone point out how to a. run the 5.1.16 bash and/or b. use cp --backup=numbered on mac os12 (and/or c. weigh in on whether the bash version is what is breaking my cp command?)


Solution

  • In answer to your three questions:

    1. Add /opt/homebrew/Cellar/bash/5.1.16/bin/bash (or better, opt/local/bin/bash which is the symlink to it) to /etc/shells
    2. The cp version that comes with macOS differs from the GNU version. It lacks the --backup=numbered option. You will need to install GNU Coreutils from Homebrew to obtain the behavior you want. The GNU cp command will be prefaced with g as in gcp for GNU cp.
    3. Neither the bash nor zsh versions have anythig to do with the cp command's options or behavior.