I look at the first eye of the shell

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.