Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ${2:-${1}} mean in Bash?

Tags:

bash

What does the following bash snippet do exactly? ${2:-${1}}

like image 419
Ben McCann Avatar asked Jul 22 '09 05:07

Ben McCann


People also ask

What does ${ 1 mean in bash script?

- 1 means the first parameter passed to the function ( $1 or ${1} ) - # means the index of $1 , which, since $1 is an associative array, makes # the keys of $1. - * means the values of of the # keys in associate array $1.

What does 2 >& 1 mean in shell script?

1 "Standard output" output file descriptor. The expression 2>&1 copies file descriptor 1 to location 2 , so any output written to 2 ("standard error") in the execution environment goes to the same file originally described by 1 ("standard output").

What is ${ in shell script?

Here are all the ways in which variables are substituted in Shell: ${variable} This command substitutes the value of the variable. ${variable:-word} If a variable is null or if it is not set, word is substituted for variable.

What does [- Z $1 mean in Bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.


1 Answers

"Use the second argument, but if none then the first one".

like image 130
Alex Martelli Avatar answered Sep 22 '22 12:09

Alex Martelli