Installing and Switching Shells

Quick reference for installing Bash, Zsh, Fish, and Tcsh on Ubuntu plus notes on printf escaping differences.

Oct 31, 2023 · 1 min read · 113 Words · -Views -Comments · Programming
Linux 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover