The word on the street is that macOS Catalina will switch to using zsh
instead of bash as the default shell. If you use bash as your default
shell and plan to upgrade to Catalina, this change will probably break
some things for you in weird ways. Regardless of that, though, the version
of bash that ships with macOS is very old and should probably be updated
anyway.
One way to get a current version of bash on macOS is to install via
Homebrew:
brew install bash
However you prefer to get bash is up to you. However, the next two steps
are the same regardless -
Now, to use this version of bash (or any other shell, for that matter),
you need to add the path of the shell to the list of "allowed" shells:
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
Next, you need to change your shell to use your version of bash:
chsh -s /usr/local/bin/bash
References:
- https://support.apple.com/en-us/HT208050
- https://linux.die.net/man/5/shells
- https://clubmate.fi/upgrade-to-bash-4-in-mac-os-x/
https://gist.github.com/JoshuaEstes/2627607#file-bash-cheat-sheet-md
Use the command as follows:
some-command 2>&1Or:
some-command > myfile.txt 2>&1Use the command as follows:
echo "Hello, World" 1>&2
echo "Hello, World" >&2The second form is short-hand for the first.
See here for more details.
Use for combined with seq to implement a C-style for loop:
for i in `seq 0 9`; do echo $i; doneAnd you can do fun stuff like this:
for i in `seq -f "%02g" 99 -1 0`; do echo "$i bottles of beer on the wall"; doneUse awk to omit the first N rows. For example:
ls -l | awk '{ if (NR > 1) print }'