Significance of ':-' while accessing a variable

Hi

I was trying to understand what ':-' means when used with variables

 
echo ${x:-10}
 
if [ "${OSH_compileFlag:-}" = "1" ]

Thanks

I do not know if -10 is a valid argument, i thought it needs a positive integer.

echo ${x:a:b}
a=start
b=number to select
x=1234567890
echo ${x:2}
34567890

echo ${x:2:4}
3456

The above is actually creating the variable with value 10 and the variable exists for only one time use. The second attempt to access the variable says it isn't defined (blank value)

It means:

${parameter:-word}
    Use Default Values. If parameter is unset or null, the expansion of word shall be substituted; otherwise, the value of parameter shall be substituted.

See Shell Command Language: 2.6.2 Parameter Expansion

2 Likes

Many Thanks for mentioning the reference :slight_smile: