DEV Community

Discussion on: Handling Arguments in Bash Scripts

Collapse
 
rpalo profile image
Ryan Palo

You're totally right, this is a good way to do it too. Thanks! Personally, I don't like set -u, because I like having blank variables, but I'm aware that maybe that makes me weird.

That being said, knowing about default and required parameter syntax is a really useful and important skill, and I'm definitely going to add it to my "Advanced Argument Handling" post. Thanks for bringing it up!

Collapse
 
exadra37 profile image
Paulo Renato • Edited

The -u flag have saved me a lot of bugs and can save you to delete the wrong path in your disk rm -rf ~/${UNSET_VAR} will be a disaster when used in some script.

If you like to have empty vars in your script then be explicit and initiate them with VAR="".

Thread Thread
 
xanderxaj profile image
Alex Palmer • Edited

This reminds me of that time running Steam (the PC video game client) would delete everything your user could delete on Linux.

It ran this code:

rm -rf "$STEAMROOT/"*

Moving the Steam install location would cause STEAMROOT to be blank...

rm -rf "/"*

Let's hope you didn't run it as root.