BASH: "local var = $ {3-16}", which means it is not clear

Trying to understand some BASH script I ran into this line

local var=${3-16}

I understand the job part and the local part - my question is that the dash points to "$ {3-16}".

If I try:

 $ maxi=${1-45}; echo $maxi
 45 <-- result

Please explain the meaning of the stroke. Thanks

+4
source share
2 answers

When executed ${parameter-default}(or ${parameter:-default}), if parameternot set, it will use the value default.

So, in var=${3-16}, if $3not set, there varwill be 16, otherwise it varwill $3.

Advanced Bash -Scripting Guide .

+10

" , ...". (:- " ".) , ${3-16} "$3, , 16".

+10

Source: https://habr.com/ru/post/1569707/


All Articles