1

I seem at example 9-14.

$ echo ${1:-0}
$ 0
$ echo ${2:-32767}
$ 32767

So I cant understand...

codeforester
  • 39,467
  • 16
  • 112
  • 140
dingding
  • 13
  • 1
  • 3

2 Answers2

8

Per the Bash Reference Manual, ยง3.5.3 "Shell Parameter Expansion":

${parameter:-word}

If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

So, for example, this script:

echo "${foo:-1}"
foo=2
echo "${foo:-3}"
foo=
echo "${foo:-4}"

prints

1
2
4
ruakh
  • 175,680
  • 26
  • 273
  • 307
3

The syntax is ${var:-$DEFAULT}. It means if the variable is not set or is null, use the default value.

Akash Dathan
  • 4,348
  • 2
  • 24
  • 45