I see Shell the first eye
1 , script interpreter settings
first line of the script: #!/bin/sh
[email protected] sun]# cat test.sh
#!/bin/sh
First Firstrows can be split into two parts,#!and absolute paths,#!It's just a special notation,#!The interpreter address is stored in the back (i.e.Shellstorage path). Note thatShellThe path must be a full path. In fact, the first line is not a non-writable, can be omitted, do not write the first line, you can manually specifyShell, such as:sh test.sh,manually SpecifyShell,The script file does not have to require execute permissions.
2 , Shell the process of executing the script
a , execute interactive commands
the user enters the terminal,Shellthe process has been run, the user enters a command, if it isShellinternal commands, such ascd,exec),a new process is not created at this time, and the internal command is actuallyShella child function in the current process is completed. If it is an external command (for example,ls,RM), youShellprocess will firstForka child process that invokesexecexecutes the command that the parent process callsWait ()orwaitpid ()to wait for the child process to end.
b , execute the script file
shell fork exec Execute the script file. This time execute exec exec start execution, and the contents of the script file are passed as arguments to the interpreter.
3 , view current usage Shell the method
( 1 ) Echo $SHELL
[Email protected] desktop]# echo $SHELL
/bin/bash
( 2 ) PS
[[Email protected] desktop]# PS
PID TTY Time CMD
3246 pts/0 00:00:00 Bash
3269 pts/0 00:00:00 PS
(3) Enter a non-existent command, ABCD
[Email protected] desktop]# ADCD
Bash:adcd:command not found
( 4 ) Ehco
[Email protected] desktop]# Echo
/bin/bash
This article is from the "10993620" blog, please be sure to keep this source http://11003620.blog.51cto.com/10993620/1722955
I look at the first eye of the shell