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