shell - How does Bash parameter expansion work? -


i'm trying understand bash script. stumbled upon this:

dir=${1:-"/tmp"} 

what mean?

:- operator says if $1 (first argument script) not set or null use /tmp value of $dir , if it's set assign it's value $dir.

dir=${1:-"/tmp"} 

is short for

if [ -z $1 ];         dir='/tmp' else         dir="$1" fi 

it can used variables not positional parameters:

$ echo ${home:-/tmp} # since $home set displayed. /home/codaddict $ unset home   # unset $home. $ echo ${home:-/tmp} # since $home not set, /tmp displayed. /tmp $  

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -