For the set in the shell and the use of eval:
Set position parameters (same as command line script)
The role of Eval is to describe the second time
[Email protected]:/home/xpg# set--Hello Shanghai Liangge [email protected]:/home/xpg# eval echo \$$ #liangge [email PR otected]:/home/xpg#
The role of "$" inside the shell:
$: script Name
If you want to get the path to the script and the name of the script, you can use DirName and basename
[Email protected]:/home/xpg# dirname/home/xpg/1.sh/home/xpg[email protected]:/home/xpg# basename/home/xpg/1.sh 1.sh
$n: Output Specific parameters
$#: Total number of parameters
$*: And the following [email protected] is the same without the quotation marks
[Email protected]: The difference with the quotation marks. You can use set to set the position parameters to see, these two generally do not
$?: The judgment of the previous command, if correct, is 0, otherwise nonzero
Usage of $ in enterprise:
Determine script command, whether the script executes successfully
* If in the script, use Exit N to return the number to $?
* If you use return in the function, return the number to $?
$$: Get the script's process number
The example of production is the execution of a script multiple times, the first time did not finish, the second is to first remove the PID of the script, in the use of $$ to determine the PID of the script
Built-in commands for bash shell:
Echo
-N: Do not wrap output content
-E: Parsing the escape character (used below)
\ n: Line break
\ r: Enter
\t:tab Jian
\b: Backspace
[Email protected]:/home/xpg# echo me;echo youmeyou[email protected]:/home/xpg# echo-n me;echo youmeyou[email protected] :/home/xpg# printf "log\tlog\npog\tpog\n" log logpog pog[email protected]:/home/xpg# echo-e "Log\tlog\npog\tpog" Log logpog pog[email protected]:/home/xpg# echo-e log\tlog\npog\tpog Logtlognpogtpog
EXEC: Executing the command will exit the current shell.
[Email protected]:/home/xpg# exec datemon Jan 07:07:25 PST 2018[email protected]:~ about shell variable quantum string knowledge and practice ${variable name}: Value ${#变量名} : Length ${variable name: num}: From num to the end, Num is a number ${variable name: num:num1}: Character ${variable name from num to NUM1 #word}: Remove the shortest matching word substring ${variable name from the beginning of the variable # #word} : delete longest matching word substring ${variable name from the beginning of the variable%word}: percent of percent removed from the right: delete the matching longest match from the right of the variable Word,word can be (A*c represents yes A to c,[0-9]) ${parameter/pattern/ String}: Use the first instead of the first matching pattern${parameter//pattern/string}: Use string instead of all pattern to modify the file name: Anaconda-ks.cfg stu_102_1_ Finished.jpg[[email protected] ~]# rename "_finished" "" *.jpg[[email protected] ~]# lsanaconda-ks.cfg stu_102_1.jpg
Inside the shell the meaning of the beginning of the $, as well as the extension