BASH SUBSTIUTION OPRATOR

     operator
           example
           rresult
       #
   ${var#pattern}
  delete the shortest match of
pattern from the front and
return the test.
     ##
  ${var##parttern}
  delete the longgest match of
the pettern from front of the var
and return the rest
    %
  ${var%pattern}
  delete the shortest match of
pattern from the end of var,
return the rest
   %%
  ${var%%pattern}
  delete the longgest march of
pattern from the end of var
return the rest
    /
   ${var/pattern/string}
 replace the longest match of
pattern with string, replace only
the first mattch
   //
   ${var//pattern/str}
 replace the lonnest match of
pattern with str, replace all
matches

BASH SUBSTITUTION OPERATOR

   operator
       example
       result
  :-
   ${var:-word]
if var exists and nonone, return
its value, otherwise return word.
var is not changed
  :=
    ${var:=word}
if var exists and nonone.then
return the var, otherwise assign
the word to var, return new value
  :+
  ${var:+owrd}
if var exists and nonone,return
word, else return null
  :?
   ${var:?message}
if var exists and nonone, then
return value, else rethrn thr
message"basg2:$var:$message"
and abort the current command
 :n
   ${var:offset[:length]}
return the length of the substring
from the offset. If length iis not,
then return the last part string.


你可能感兴趣的:(BASH SUBSTIUTION OPRATOR)