mindthump

Bash Parameter Substitution and Expansion

Jul 19th, 2020 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.00 KB | None | 0 0
  1. Expression         Meaning
  2. ----------         --------
  3. ${var}             Value of var (same as $var)
  4. ${var-$DEFAULT}    If var not set, evaluate expression as $DEFAULT *
  5. ${var=$DEFAULT}    If var not set, evaluate expression as $DEFAULT *
  6. ${var:-$DEFAULT}   If var not set or is empty, evaluate expression as $DEFAULT *
  7. ${var:=$DEFAULT}   If var not set or is empty, evaluate expression as $DEFAULT *
  8. ${var+$OTHER}      If var set, evaluate expression as $OTHER, otherwise as null string
  9. ${var:+$OTHER}     If var set, evaluate expression as $OTHER, otherwise as null string
  10. ${var?$ERR_MSG}    If var not set, print $ERR_MSG and abort script with an exit status of 1.*
  11. ${var:?$ERR_MSG}   If var not set, print $ERR_MSG and abort script with an exit status of 1.*
  12. ${!varprefix*}     Matches all previously declared variables beginning with varprefix
  13. ${!varprefix@}     Matches all previously declared variables beginning with varprefix
  14.  
  15. * If var is set, evaluate the expression as $var with no side-effects.
Add Comment
Please, Sign In to add comment