Shell: get started with Linux, OS X, and Unix Shell Environments
In Linux or Unix-like systems, each user and process runs in a specific environment. This environment contains variables, settings, aliases, functions, and more. The following is a brief introduction to some common commands in the Shell environment, including examples of how to use each command, and setting your own environment under the command line to improve efficiency.
Find your current shell
Enter any of the following commands in the terminal application:
ps $$
ps -p $$
Or
echo "$0"
Output example:
Figure 1: Find the Current shell
Find all installed Shells
Find the complete path of the installed shell:
type -a zsh
type -a ksh
type -a sh
type -a bash
Output example:
Figure 2: Find the shell path
The/etc/shells file contains the list of shells supported by the system. Each line represents a shell, which is the complete path relative to the root directory. Run the cat command to view the data:
cat /etc/shells
Output example:
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/fish
Temporarily change the current shell
You only need to enter the shell Name. In the following example, I switched from bash to zsh:
zsh
This only temporarily changes the system shell. It is also called a sub-shell. To exit from the child/Temporary shell, enter the following command or press the CTRL-D:
exit
Find the sub-shell level or the nested level of the temporary shell
After each bash instance is started, the value of $ SHLVL is added. Enter the following command:
echo "$SHLVL"
Sample output:
Figure 3: Bash shell nested hierarchy (number of sub-shells)
Use the chsh command to change the system shell permanently
Want to change the current system shell from bash to zsh permanently? Try this:
chsh -s /bin/zsh
Want to change the shell of another user from bash to ksh permanently? Try this:
sudo chsh -s /bin/ksh userNameHere
For more details, please continue to read the highlights on the next page: