Linux shell

From 太極
Jump to navigation Jump to search

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

https://www.howtogeek.com/68563/htg-explains-what-are-the-differences-between-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

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.

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