1, shell Introduction
Shell is written in a C language script language, which is a bridge Linux user, user input command to the Shell process, the Shell operation corresponding to the kernel (Kernel), the kernel outputs the result of the processing to the user.
The following is a schematic flow diagram:
2, view the shell
Shell is a program, usually placed in the / bin or / user / bin directory, the current Linux system available Shell are recorded in the / etc / shells file, you can use the cat command to view it;
╭─[email protected] ~
╰─➤ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/zsh
View the current default Shell Linux, then you can output SHELL environment variable:
╭─[email protected] ~
╰─➤ echo $SHELL
/bin/zsh
3, execute the shell script
Three ways to execute a shell script
ource filename
source filename: This command is really just simply read the script inside the statement sequentially executed in the current shell inside, not creating a new sub-shell. The script all new inside, change the variable of statement will be saved in the current shell inside.
bash filename
bash filename to re-establish a sub-shell, execute the script inside the statement in the sub-shell, the shell sub-shell environment variables inherited his father's, but the new sub-shell, variables will not be changed back to the parent shell.
./filename
./filename:; "." When the shell script has executable permissions, and ./filename execute the script with bash filename is no difference between ./ filename is because the current directory is not in the PATH, it is used to indicate the current directory .
Child and parent shell shell
Features: New sub-shell variables do not take effect in the parent shell
╭─[email protected] ~
╰─➤ pstree
systemd─┬─NetworkManager───2*[{NetworkManager}]
├─auditd───{auditd}
├─chronyd
├─crond
├─dbus-daemon
├─gssproxy───5*[{gssproxy}]
├─login───zsh
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5*[{polkitd}]
├─rpcbind
├─rsyslogd───2*[{rsyslogd}]
├─sshd───sshd───zsh───pstree
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─tuned───4*[{tuned}]
└─vmtoolsd───{vmtoolsd}
╭─[email protected] ~
╰─➤ bash
[root@localhost ~]# pstree
systemd─┬─NetworkManager───2*[{NetworkManager}]
├─auditd───{auditd}
├─chronyd
├─crond
├─dbus-daemon
├─gssproxy───5*[{gssproxy}]
├─login───zsh
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5*[{polkitd}]
├─rpcbind
├─rsyslogd───2*[{rsyslogd}]
├─sshd───sshd───zsh───bash───pstree
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─tuned───4*[{tuned}]
└─vmtoolsd───{vmtoolsd}
[root@localhost ~]# age=25
[root@localhost ~]# echo $age
25
[root@localhost ~]# exit
exit
╭─[email protected] ~
╰─➤ echo $age
4, shell conventions
Naming conventions 1: See name known Italian
command conventions 2: ending .sh
Content writing:
#!/bin/bash #声明shell解释器
echo "Hello World" #执行的command