Skip to content

Instantly share code, notes, and snippets.

@aprell
Created November 9, 2015 19:49
Show Gist options
  • Select an option

  • Save aprell/ff06a0a3ccf116a44bec to your computer and use it in GitHub Desktop.

Select an option

Save aprell/ff06a0a3ccf116a44bec to your computer and use it in GitHub Desktop.
Shell parameter expansion
#!/bin/bash
# Use if unset or null
echo ${x:-x} # x
echo $x #
# Assign if unset or null (only regular variables)
echo ${y:=y} # y
echo $y # y
# Error if unset
z=
echo ${z?} #
# Use if not null
echo ${z+z} # z
# Error if unset or null
echo ${z:?} # parameter null or not set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment