0
STACK="${2:-}"
shift
;;

What does the following code mean in shell script? Specifically what does ${2:-} mean? Looks like it is assigned to a variable.

Jens
  • 69,818
  • 15
  • 125
  • 179
Tanvi Jaywant
  • 375
  • 1
  • 6
  • 18
  • 1
    Possible duplicate of [What's the difference between :- and := in Bash parameter substitution?](https://stackoverflow.com/questions/48218775/whats-the-difference-between-and-in-bash-parameter-substitution) – iamauser Oct 18 '18 at 16:10
  • 1
    Please read the section about *parameter expansion* of your shell (maybe `man sh` does the trick). It's all explained in there, with all variants. – Jens Oct 18 '18 at 16:37

1 Answers1

1

${2:-} means, if the 2nd parameter is unset or null, empty will be assigned to it. Eg:

$ a=         # passed empty to a
$ echo $a    # prints empty or nothing

$ echo ${a:-test}  # prints test
test
Jens
  • 69,818
  • 15
  • 125
  • 179
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58