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*

7
  • 6
    set -u will do what you want. Commented Jun 8, 2015 at 6:27
  • can you make it as the answer? Commented Jun 8, 2015 at 6:27
  • 2
    Of course you wouldn't initialize your vars to empty strings. [ -z "$VAR" ] works with an uninitialized VAR too. The initialization was just to show the undesirable behavior—My point is, if your vars ever do become initialized to empty strings, in whatever way, and you run rm -r "$PROJECT_HOME"/* mistakenly relying on set -u, you will get the "apocalyptic" behavior. IHMO, it's better to be safe than sorry when it comes to protecting the entire contents of your computer. set -u is not safe. Commented Jun 8, 2015 at 8:00
  • 3
    "It is very long"? You should not be looking for a convenient way to manually perform dangerous operations. Instead, you should create a function, alias, or script to do what you want; in this case, making in an alias from @PSkocik's suggested command will be both safe and convenient. Commented Jun 8, 2015 at 17:32
  • 1
    What if the user sets PROJECT_HOME=/etc? Just checking for an empty value is not enough to prevent cataclysm. You shouldn't use variables from untrusted users when running as root. Commented Jun 10, 2015 at 19:40