Installing and Switching Shells

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

  1. In Bash and Zsh, printf "PreExecMarker;$1"; doesn’t escape arguments, so placeholders like date +%Y can trigger errors. Fish and Tcsh automatically escape arguments and avoid the issue.

    https://static.1991421.cn/2023/2023-10-31-195452.jpeg

    Fix it by specifying the format explicitly:

    printf "PreExecMarker;%s" "date +%Y"
    

    https://static.1991421.cn/2023/2023-10-31-195625.jpeg

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源