Jump to content

Linux shell

From 太極

Different shells

Run multiple shells

How To Run Multiple Shells In Linux: Bash, Fish, Zsh And More

Difference Between Bash, Zsh, and Other Linux Shells

What’s the Difference Between Bash, Zsh, and Other Linux Shells

sh (Bourne shell, 1977)

  • Basic shell
  • POSIX-compliant shell

Bash shell

  • Can be mostly POSIX compliant
  • Expose array indices
  • Regular expression conditionals
  • Increment assignment operator
  • Current version: Bash 4

Bash shell programming

Dash

  • Mostly compatible with Bash
  • POSIX compliant
  • Low-memory usage
  • Faster execution
  • Doesn't have a command history
  • Not easily installed in CentOS 7 (though popular in Debian OS)

zsh shell and Oh my zsh

  • How to Install ZSH Shell on Ubuntu 18.04 LTS
    • Installing ZSH Shell
    • Making ZSH the Default Shell
    • Installing Powerline and Powerline Fonts for ZSH
    • Installing ZSH Powerlevel9k Theme
    • Enable Syntax Highlighting on ZSH Shell
    • ZSH and Git Integration with Oh-My-ZSH (https://ohmyz.sh/)
    • Changing Oh-My-ZSH Theme
    • Enabling Oh-My-ZSH Plugins
    • I can further change the color scheme in iTerm2 preferences in macOS or Terminator preferences in Ubuntu from the Profile tab. On Ubuntu, I can choose 'Tango' (looks good) or 'Solarized' (the colors on the filenames are too light). On iTerm2, I choose 'Tango (light)' or 'Pastel (Dark Background)'.
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
nano .zshrc  # change ZSH_THEME to "agnoster"
             # add RPROMPT='%*'
     # add prompt_context(){} at the bottom of your ~/.zshrc to hide the “user@hostname” info
sudo apt install fonts-powerline
  • How to change from zsh to bash? Changing your shell, via sudo chsh --shell=/bin/bash $USER will change the shell field in /etc/passwd. This value is only consulted at login time, when the system has no idea of which shell to use for you. Running processes, whether started by zsh, bash apache or evil_overlord's_program won't be affected.
    • When I try to change the shell to zsh to bash, I use sudo usemod but choose the wrong location '/usr/bin/bash' (it should be /bin/bash). The result is when I try to reconnect to Pi, it always said the password is not correct. Fortunately I can shutdown Pi, move the SD card to chromebox and run sudo nano /var/host/media/removable/rootfs/etc/passwd to fix the bash path.
  • How can you export your .bashrc to .zshrc?
  • Use .zshrc to do things like
    • Export environment variables
    • Set command aliases
    • Set non-default Bash Options by using setopt
  • scp with zsh : no matches found. This is because the wildcard expansion is not enabled by default in zsh. One solution is to add a double quote. For example, scp "username@hostname:Downloads/*.txt" ~/Downloads. Another way is to add this to your .zshrc
    alias scp='noglob scp'
    # OR
    setopt nonomatch
    

The more you customize, the less portable your config can become. The more you add to your shell, the more time it can take to start up and to run basic commands. Be selective when you customize.

Powerlevel10k theme

  • https://github.com/romkatv/powerlevel10k
  • The rainbow style is used by Manjaro KDE. The classic style is used by ElementaryOS.
  • Install and Use Powerlevel10k in Zsh
    $ sudo apt install git fonts-font-awesome
    $ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    
    $ nano ~/.zshrc # ZSH_THEME="powerlevel10k/powerlevel10k"
    $ source ~/.zsrhc
    # Answer questions step-by-step. Or call the following to re-configure
    # p10k configure
    
  • It works by testing on Debian 12 running GNOME.
    • Reboot is helpful to really see the effect.
    • We will see an arrow in the prompt.
  • There is no need to change the default font (Monospace) in the Terminal app.
  • If I need to configure it again, run p10k configure in the terminal. The configuration file is saved at ~/.p10k.zsh.

Enable Timestamp For History Command

Enable Timestamp For History Command In Zsh In Linux. Use the -f flag to print full date and time stamps.

history -f
history -i

fc -lf

history in zsh is the same as fc -l. See zsh Shell Builtin Commands.

Fish shell

  • Features
    • Most compatible with Bash
    • Designed for interactivity
    • Syntax highlighting on the CLI
    • Interactive autosuggestions
    • Cleaner syntax for conditions and loops
    • Only available in third-party EPEL software repository