Quotation marks in xshell
Single quotation marks: What you see is what you get, what you eat is what you spit out
Double quotes : special symbols inside will be parsed
What is a shell?
A command interpreter that translates the commands we type and returns them to the user upon successful execution
1
The default shell for linux is (bash)
What is a shell script?
A collection of commands Many executable commands put in text to become a shell script
1
Shell script specification (ready for automation)
Must be placed in the same directory
Scripts must end in .sh
Scripts must start with a comment #! /bin/bash must be the first line, anything other than that is a comment
**Comment information for scripts **
English is recommended for comments
Pairs of symbols and syntax are written at once
Naming of script names preferably by name
shell special location variables
$0: represents the name of the script, if the full path is executed, the script name with full path
[root@localhost ~]#sh test.sh
test.sh
[root@localhost ~]#sh /etc/test.sh
/etc/test.sh
[root@localhost ~]#basename /etc/test.sh
test.sh
Contents of test.sh:
#! /bin/bash
echo $0
$n nth argument of the script 0 is occupied by the name of the script starting from 1 9 the arguments after 9 should be enclosed in {} {10}
[root@localhost ~]#sh /etc/test.sh oldboy1 oldboy2
oldboy1
oldboy2
test.sh reads.
#! /bin/bash
echo $1
echo $2
[root@localhost ~]#echo -e ‘#! /bin/bash\necho `pwd`’ >test.sh
[root@localhost ~]#sh test.sh
/root
$# Get the total number of parameters passed by the script
∗ Get all parameters of the script without parentheses and ∗ ∗ ∗ ∗ * Get all parameters of the script without parentheses and ** ** ∗ Get all parameters of the script without parentheses and ∗∗∗∗@ Same Add double quotes to treat the parameters as one parameter
@ Get all parameters of the script without parentheses and ** ** @ Get all parameters of the script without parentheses and ** ** @ Get all parameters of the script without parentheses and ∗∗∗∗ Same plus double quotes then treat the parameter as one parameter *
$? Get the result of the previous command. 0 is success, not 0 is failure.
[root@localhost ~]# echo 1
1
[root@localhost ~]# echo $?
0
[root@localhost ~]# ll xxxxx
ls: cannot access xxx: No such file or directory
[root@localhost ~]# echo $?
$$:Get the PID of the script
$! :Get the PID of the last script running in the background Debug use
$_: Get the last parameter of the command line
String deletion and replacement
[root@localhost ~]# url=www.google.com
[root@localhost ~]# echo ${url}
[root@localhost ~]# echo ${url#*.}
[root@localhost ~]# echo ${url##*.}
[root@localhost ~]# url=www.baidu.com
[root@localhost ~]# echo ${url}
www.baidu.com
[root@localhost ~]# echo ${url%. *}
www.baidu
[root@localhost ~]# echo ${url%%. *}
www
[root@localhost ~]# echo ${url}
[root@localhost ~]# echo ${url/w/a}
[root@localhost ~]# echo ${url//w/a}