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*

3
  • From a correctness perspective, I have nothing to add to this -- it's a good answer (and a little more paranoid about hewing to the POSIX sh specification than mine, which relies on behavior that bash implements but doesn't document terribly well). That said -- what's up with the formatting? > principally used to indicate that one is quoting text; presumably it has a different meaning here. Commented Dec 7, 2015 at 23:09
  • Thanks for your answer. I especially like the use of :-. I chose Charles's only because it was first and had the array solution as well, but there's some neat stuff here. From some experimenting, I see that if foo=, then ${foo:-} will be an omitted parameter whereas ${foo:-""} will be the empty string. Cool. Commented Dec 7, 2015 at 23:13
  • cool , me the > format just helps to visually distinguish between code and output. Of course its always helpful if your code is portable Commented Dec 7, 2015 at 23:14