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

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - How can I merge Nodes & Webform Submissions into instances of one general Content Type in Drupal 6? -