9. Parameter expansion

9.1. Simple usage

  • $PARAMETER

  • ${PARAMETER}

9.2. Indirection

  • ${!PARAMETER}

9.3. Case modification

  • ${PARAMETER^}

  • ${PARAMETER^^}

  • ${PARAMETER,}

  • ${PARAMETER,,}

  • ${PARAMETER~}

  • ${PARAMETER~~}

9.4. Variable name expansion

  • ${!PREFIX*}

  • ${!PREFIX@}

9.5. Substring removal (also for filename manipulation!)

  • ${PARAMETER#PATTERN}

  • ${PARAMETER##PATTERN}

  • ${PARAMETER%PATTERN}

  • ${PARAMETER%%PATTERN}

9.6. Search and replace

  • ${PARAMETER/PATTERN/STRING}

  • ${PARAMETER//PATTERN/STRING}

  • ${PARAMETER/PATTERN}

  • ${PARAMETER//PATTERN}

9.7. String length

  • ${#PARAMETER}

9.8. Substring expansion

  • ${PARAMETER:OFFSET}

  • ${PARAMETER:OFFSET:LENGTH}

9.9. Use a default value

  • ${PARAMETER:-WORD}

  • ${PARAMETER-WORD}

9.10. Assign a default value

  • ${PARAMETER:=WORD}

  • ${PARAMETER=WORD}

9.11. Use an alternate value

  • ${PARAMETER:+WORD}

  • ${PARAMETER+WORD}

9.12. Display error if null or unset

  • ${PARAMETER:?WORD}

  • ${PARAMETER?WORD}