bashstyle icon indicating copy to clipboard operation
bashstyle copied to clipboard

Using defaults and "${VAR:?}"

Open stuartpb opened this issue 10 years ago • 3 comments

If you don't assert the existence of certain important variables, your script could inadvertently wipe the user's home directory:

https://github.com/ValveSoftware/steam-for-linux/issues/3671

https://news.ycombinator.com/item?id=8896186

stuartpb avatar Jan 16 '15 14:01 stuartpb

There's also set -u

stuartpb avatar Jan 16 '15 14:01 stuartpb

I generally don't like set -u, but I do like "${foo:?}" when needed.

progrium avatar Jan 16 '15 17:01 progrium

I'm not into set -u either, but it's worth noting for people who want to write their own style guides. (It's also worth noting as a "critical section" wrapper that can be paired with set +u.)

stuartpb avatar Jan 16 '15 19:01 stuartpb