10. Parameter expansion

10.1. Simple usage

  • $PARAMETER
  • ${PARAMETER}

10.2. Indirection

  • ${!PARAMETER}

10.3. Case modification

  • ${PARAMETER^}
  • ${PARAMETER^^}
  • ${PARAMETER,}
  • ${PARAMETER,,}
  • ${PARAMETER~}
  • ${PARAMETER~~}

10.4. Variable name expansion

  • ${!PREFIX*}
  • ${!PREFIX@}

10.5. Substring removal (also for filename manipulation!)

  • ${PARAMETER#PATTERN}
  • ${PARAMETER##PATTERN}
  • ${PARAMETER%PATTERN}
  • ${PARAMETER%%PATTERN}

10.6. Search and replace

  • ${PARAMETER/PATTERN/STRING}
  • ${PARAMETER//PATTERN/STRING}
  • ${PARAMETER/PATTERN}
  • ${PARAMETER//PATTERN}

10.7. String length

  • ${#PARAMETER}

10.8. Substring expansion

  • ${PARAMETER:OFFSET}
  • ${PARAMETER:OFFSET:LENGTH}

10.9. Use a default value

  • ${PARAMETER:-WORD}
  • ${PARAMETER-WORD}

10.10. Assign a default value

  • ${PARAMETER:=WORD}
  • ${PARAMETER=WORD}

10.11. Use an alternate value

  • ${PARAMETER:+WORD}
  • ${PARAMETER+WORD}

10.12. Display error if null or unset

  • ${PARAMETER:?WORD}
  • ${PARAMETER?WORD}