Shell
Choices
- SH - for maximum compatibility
- Bash (Bourne Again Shell)
- Traditional, widely available.
- (Relatively) slow.
- Lacking in interactive features.
- Zsh
- Default on macOS.
- Modern, feature rich.
- More powerful scripting syntax than Bash.
- Fish
- User-friendly, not POSIX compliant, more ergonomic.
- Best for interactive use.
- Nushell, similar to PowerShell, everything is an object. Could be helpful in batch processing things.
- Fast shells
INFO
The benchmark on my MacBook Pro M3 Pro demonstrates that
fishis the fastest overall, even compared todashandmksh.
Snippets
# Batch copy and substitute file name.
for f in good*.bminor; do cp "$f" "${f//good/bad}"; done
{ cmd1; cmd2; cmd3 } > /dev/null # group stdout of commands
cat ... | head -n -5 | tail -n +5 # exclude 5 lines at begining or end
tail -f file # watch the tail of a file
\ls # precede command with backslash to suppress aliases
pstree; vmstat; tload
set # prints all variables
env; printenv # prints only env vars- Use
Alt/Opt-FandAlt/opt-Bto go forward/backward a word! - Many other Emacs keybinding can be used as well.
- Pressing and releasing the
Esckey has the same effect as holding downAltkey (on a real terminal) Alt-?displays all possible completions,Alt-*inserts all possible completions.-optionis called “BSD style”!- Login shells read
profiles, non-login shells readrcfiles. Non-login shells also inherit env vars from login-shells. - Shell variables are not inherited, env variables are.
Other Concepts
- ANSI Escape Code
033(the code generated by ESC), optional character attribute, and an instruction.\033[0;30m(black) and\033[1;30m(dark grey), the0and1are bolt attribute.- Non-printing characters should be wrapped in
\[\]. - Escape codes can also be used to move cursor around.
.bash_profileis only used for login shells..bashrcis used for interactive shells.
Shell Prompt
- Powerline, and Powerlevel10k.
- Starship, cross platform and customizable, written in Rust, successor of Spacefish, a Fish implementation of Spaceship.
- Spaceship, for Zsh only.