Installing and Switching Shells
10月 31, 2023
·
1 分钟阅读时长
·
113
字
·
-阅读
-评论
While adding shell hooks to a web shell project, I hit a few quirks. Here’s a cheat sheet for installing various shells and switching between them, using Ubuntu as the example OS.
Bash
chsh -s $(which bash)
# Version
bash --version
Zsh
sudo apt install zsh
chsh -s $(which zsh)
# Version
zsh --version
Fish
sudo apt install fish
sudo chsh -s $(which fish)
Tcsh
sudo apt install tcsh
chsh -s $(which tcsh)
Notable Differences
In Bash and Zsh,
printf "PreExecMarker;$1";doesn’t escape arguments, so placeholders likedate +%Ycan trigger errors. Fish and Tcsh automatically escape arguments and avoid the issue.
Fix it by specifying the format explicitly:
printf "PreExecMarker;%s" "date +%Y"

