▲ | fireflash38 3 days ago | |
One of my major nitpicks with set -e isn't from bash... It's from poorly behaved programs you might run. Ones that don't exit with defined exit codes (non-zero on error!). | ||
▲ | inetknght 2 days ago | parent [-] | |
> Ones that don't exit with defined exit codes (non-zero on error!). My favorite is `docker images`. It outputs... not-empty when the output is empty. It returns zero (success) when output is not-empty and empty. So you have to both do error checking and parse its output before you know whether there are any matching images in the cache. Contrast that with grep. You can do `if grep -q foo` or `if grep -qv foo`, you can do `if "foo" == "$(grep foo)"`, etc. Much more versatile and easy to use. Then there's apps that report to stderr that some argument isn't used but then also exits with success without doing things. Then there's similar apps that do the same thing but... exits after also doing things. Ugh. After some time you get to learn to test your apps before you write up scripts around them. That's a good thing though, it means that you know how to mix together a diverse toolset. |