I do not understand this parameter extension: $ {p // [0-9] /}

In a Linux /etc/init.d/functionsscript, I found the following parameter extensions, which I do not quite understand:

${p//[0-9]/}  replace all instances of any number to/by what?

${1##[-+]}  This seems to remove all the longest left instances of minuses and pluses?

${LSB:-}  This seems to say that if LSB is not set then set nothing? in other words do nothing?
+4
source share
2 answers

These are examples of bash the shell parameter extension ; see http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

Note: kshand zshalso support the expansion of your question (I'm not clear about the full functionality of the ceiling), while sh(only shell POSIX-function), do not support the expansion line replacement ${p//[0-9]/}.


${p//[0-9]/}

: (//) ([0-9]) - ( / , ).

${1##[-+]}

- +, . (##), - + $1. , , ## , # - - .

${LSB:-} 

-op, script -u (nounset). : , $LSB , , , :-, .

, , Sigi :

"
${LSB:-} , -u ( set -u), $LSB . , $LSB ${LSB:-}. , set -u , .
"

+4
${p//[0-9]/} # removes digits from anywhere in `$p`

${1##[-+]} # removes + or - from start in $1

${LSB:-} # not really doing anything
0

Source: https://habr.com/ru/post/1538242/


All Articles