DEV Community

Discussion on: Bash If Statements: Beginner to Advanced

Collapse
 
apavlis profile image
apavlis • Edited

I think you stole [[ ${DEBUG} ]] from me....

bash 4.x is pretty good. You can do all sorts of fun things. Esp. with bash built-ins.

Lately ... I've been trying to make as many one line if statements as possible and use drop down logic for all practical purposes...too bad I can't do this with for & while loops.

You can also use this in aliases functions too, which makes setting up environments a snap...

mytag="Great big stuff"

[[ "${mytag}" == *"stuff"* ]] && { echo -en "${mytag/stuff/COOKIES}"; echo -en " are tasty\n"; sleep 5; } || { echo "Blech.  You don't like cookies!"; [[ ! ${someothervar} ]] && echo "hello world."; }