-
Notifications
You must be signed in to change notification settings - Fork 0
Shell
GradedJestRisk edited this page Jul 28, 2021
·
14 revisions
List:
- https://en.wikipedia.org/wiki/Almquist_shell ash - Almquist Shell
- bash - Bourne-Again Shell (a born-again Bourne shell)
- csh - C-Shell
- ksh - Korn Shell
- dash - Debian Almquist Shell (from ash)
- sh - Bourne Shell
- zsh - Zhong Shao Shell
List:
- get current interactive shell:
echo $0
ps --pid "$$"
- get parent shells:
ps -o pid,cmd --forest
$ ps -o pid,cmd --forest PID CMD 5357 /usr/bin/zsh 17522 \_ zsh -i 20461 \_ bash 20781 \_ ps -o pid,cmd --forest 18106 zsh -i
Configuration
- get installed shells
cat /etc/shells
- get default non-interactive shell
ls -ltr /bin/sh
- get default interactive shell:
echo "$SHELL"
- change default shell:
chsh
Shell can run in:
- interactive mode, so that user can tell dynamically which script to run:
bash -i
- non-interactive mode, to execute a single script (which can ask for user input):
bash -c 'echo Hello, world!'
❯ printf "Process %d is running %s" $$ $0 Process 5357 is running zsh% ❯ zsh -i ❯ printf "Process %d is running %s" $$ $0 Process 17522 is running zsh% ❯ echo $@ ❯ bash -c 'printf "Process %d is running %s" $$ $0 Process 15338 is running bash%
POSIX is a standard for shell. dash aims at POSIX-compliance.
To check your script compatibility, run your script with shellcheck
shellcheck --shell=dash ./myscript.sh
Unfortunately, 'portable' is usually a stronger requirement than 'POSIX-compliant' for shell scripts. That is, writing something that runs on any POSIX shell isn't too hard, but getting it to run on any real-world shell is harder.From here
POSIX non-compliant: - fish
Test framework for shell:
List:
- consider using strict mode
- use best practice
- lint with
spellcheck
Shortcut with Ctrl:
- cancel Y
- interrupt current command C
- clear the line
- up to the beginning: U
- forward (right): K
- downward (left): W
- several strokes: E U / A K
- go to
- beginning of the line: A
- end of the line: E
- clear screen (prompt): L