Shell script execution and basic knowledge

Source: Internet
Author: User

After we grant the shell script execution permission, we can test the program. Assume that the shell script file is hello. Sh.
In the/root directory. The following describes how to execute shell scripts on a terminal:
1. Switch to the directory where the shell script is located and execute:

[[Email protected] Home] # cd/root/
[[Email protected] ~] #./Hello. Sh
Hello guys!
Welcome to my blog: linuxboy.org!



2. Execute in absolute path mode:

[[Email protected] ~] #/Root/Hello. Sh
Hello guys!
Welcome to my blog: linuxboy.org!

3. Run bash or sh directly:

[[Email protected] ~] # Bash hello. Sh
Hello guys!
Welcome to my blog: linuxboy.org!
[[Email protected] ~] # Sh hello. Sh
Hello guys!
Welcome to my blog: linuxboy.org!

Note: run the shell script in the above three methods. The current shell will start a sub-shell environment and execute the shell script.
You can also run the shell script in the current shell:
4. Execute in the Current Shell

[[Email protected] ~] #./Hello. Sh
Hello guys!
Welcome to my blog: linuxboy.org!
[[Email protected] ~] # Source hello. Sh
Hello guys!
Welcome to my blog: linuxboy.org!
[[Email protected] ~] #

 

 

2. Similar to method 1, but it takes the script file name as the parameter.

Sh Bash. Sh

 

3. Set the script file to an execution file and call it directly at the prompt.

Chmod U + X test. Sh

./Test. Sh

Shell basics: http://www.cnblogs.com/xuejie/archive/2013/01/31/2886552.html

 

Script filename:

#!/bin/sh echo *.jpg

Chmod + x filename

./Filename to execute your script.

This will print the result of "mail.jpg tux.jpg.

 

Quotation marks (single quotation marks and double quotation marks) will prevent such wildcard extension:

#!/bin/shecho "*.jpg"echo ‘*.jpg‘

This will print "*. jpg" twice.

Single quotes are stricter. It can prevent any variable extension. Double quotation marks can prevent wildcard extension but allow variable extension.

#!/bin/shecho $SHELLecho "$SHELL"echo ‘$SHELL‘

The running result is:

/Bin/bash

/Bin/bash

$ 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.