Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • In my own convenience (bash)-scripts I do, for example, mplayer "${MPEXTRAOPTS[@]}" "$CALCULATED_FILENAME" and depend on that the "${MPEXTRAOPTS[@]}" expand to nothing (not even an empty argument) if MPEXTRAOPTS is unset. Then if I need some extra arguments to be passed, I set the array, otherwise I just let it be unset. Since scalar variables are auto-promoted (can be used as) arrays with only element [0] set, if I need just one extra argument, I would just set the variable in a scalar fashion, like MPEXTRAARGS=-fs. Commented Jun 23, 2014 at 17:03
  • Nonexistent variables do not always evaluate to an empty string. For instance: unset unset ; echo "${unset-not an empty string}" Commented Jun 24, 2014 at 2:58
  • 1
    @mikeserv, I didn't mean to imply that unset variables and empty variables were equivalent, or that using different types of parameter expansion couldn't change the answer - I was merely answering the question as posed, where all parameter expansions where of the basic ${VAR} sort. The question was "is there any harm..." and the correct answer is "not generally, and sometimes it's even helpful, though there are special cases where someone sets a flag saying that unset variables cause errors". Commented Jun 24, 2014 at 11:11
  • ok. maybe I was a little hasty. But is there anything you might edit? Not because you need to really, but I'd like to reverse my vote and can't do so unless it is edited... Commented Jun 24, 2014 at 11:23
  • @mikeserv, Sure - reworded the first clause to "Non-existent variables will always evaluate to an empty string when expanded as $FOO or (equivalently) ${FOO}", to address your concern about different flavors of parameter expansion. Commented Jun 24, 2014 at 11:26