I don’t know what to share for ARTS this week. So I summarize a little knowledge of the shell.
What is a shell
A shell is a software interface that is ofthen a command line interface that enables the user to interact with the computer. In linux, we can check all supported shell via the following way.
1 | lee@lee-server:~$ sudo cat /etc/shells |
bash( Bourne again shell) - rewrited sh, generating more functions.
What is the differnce between script execution
First situation
Execute as one child process, once the child process exists and back to parent shell, the related envs will disappear. Such as:
1 | bash script_name.sh |
envs: environmental variables.
Second situation
Execute in the current shell. envs will always work before quit. Such as:
1 | source script_name.sh |
Pip
The output of left cmd is used as the input to the right cmd. As follows:
1 | lee@lee-server:/boot/grub$ cat | ps -f # Create one new process for every external cmd. |
We should avoid to use built-in cmd in pip ,such as , ls , cd ,etc.
built-in cmd: execute in the current shell.
external cmd: create one new process, like top.
Input and output redirection
1 | "<" # input redirection. |
Variable
Definition of variables
1 | var=value |
Note: ${var}, sometimes we can only use $var, sometimes we can’t, i.e., ${var}test != $vartest.
Scope of the variable
Variable only works in the current terminal or the current shell script.
If we want to use it in the child process, we need to export it as follows:
1 | export var(=xxx) |
If we don’t need it anymore, we need to clear it as follows:
1 | unset var |
Env and others
1 | set # display the current shell variable. |
Config of linux
All user’s config
1 | /etc/profile |
Current user’s config
1 | ~/.bash_profile |
Loading order
su - root
1 | /etc/profile |
It is a better way to switch account.
su root
1 | ~/.bashrc |