0
arg2=${arg1:-}

What does this do to arg1 when assigned to arg2? I don't see any differences when printing both args

Cyrus
  • 84,225
  • 14
  • 89
  • 153
would_like_to_be_anon
  • 1,639
  • 2
  • 29
  • 47
  • From man page: `${parameter:-word}` : Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. – Wiimm Apr 13 '23 at 13:07
  • 1
    It does nothing *to* `arg1`; it does something *with* the (lack of a) value of `arg1`. – chepner Apr 13 '23 at 13:18
  • 1
    @Wiimm : Not entirely true. The difference is cruicial, when you program your script with `set -u` turned on (which, IMHO, is a good idea), and `arg1` is undefined. By distinguishing these cases, you can catch undefined variables. – user1934428 Apr 13 '23 at 13:18
  • 1
    In case of `${arg1:-}`: if unset or empty then return an empty string. – Wiimm Apr 13 '23 at 13:24

0 Answers0