Chapter III: shell variables advanced knowledge

Special variables:
time position variable is greater than 9, you need to add (), for example, $ (10)
$ * Get script of all the parameters, if not "" and $ @ is the same effect, if the words "" indicates All parameters of the composition of a string
$ 0 for the script itself, if the script add the path, the result is $ 0 plus the path
dirname to get the script path dirname /root/test.sh result: / root
basebame get the script name basename / root / test. sh results: test.sh
$$ to get the current shell process ID, prevent duplication of execution, you can check this variable
$ _ get the last argument on a script
echo -n does not wrap content output
echo -e resolve the escape character \ n newline \ t tab \ v vertical tab \ b back frame 1 \ r carriage
eval args when the execution of the script to eval, as the contents of the script execution will args
exec </tmp/test.txt while read line; do echo $ line; done exec file read read read content to the
shift so that the parameters of the script to the left a
calculated length of the string
. 1, expr length "asdas"
2, echo "asdsa" | awk '{ length Print ($ 0)} '
. 3, echo "asdsa" | -length is WC
. 4, A = "ASD sa "

time command can be used to calculate the command execution time (first known)
for A in `echo | Sed 'S / [[: punct:]] / / g'`;" I AM odlboy Linux, welconm Our tranining. " do if [$ {# a} -lt 6]; then echo $ a; fi; done print string of words less than 6
a = "123456"; echo $ {a: 2: 3} taken to the second character after three characters equals a = "123456"; echo $ a | cut -c 3-5
variable content removal and replacement
reference https://blog.csdn.net/qq_31567335/article/details/88985071
A = "asdasdasdlkaldk"; echo $ {a # a * d } begin deleting a * d shortest match from the beginning of the content
a = "123 456 789 456" echo $ {a // 456/000} variable substitution / replacement of a // replace all
shell special extended variable:
test = '' {$ echo test: -0} If test variable is empty 0 (it is quite practical) is returned
test = '' echo $ {test : = 0} will be empty if the variable test the value of the custom variable to 0, and the difference between one, but not for the position variables and special variables (this is more practical)
test = '' echo $ (test:? not defined) if the test is empty not defined returns, multi-purpose the value of the test variable is empty
test = $ {test2:+ Value} to determine whether the value here if test2 is empty, if empty, how to return empty, if there is a value, how to return value, used to test whether the variable has the value
Summary: These things are very understanding burning brain, how he invented? ? ? Maybe I understand the poor? -?

Guess you like

Origin www.cnblogs.com/sxdpython/p/12601632.html