Kearney Taaffe Kearney Taaffe - 3 months ago 5
Bash Question

what does [ -n "$VARIABLE" ] || exit 0 mean

Looking at correcting an issue in /etc/init.d/hostapd on Debian. However, I have no clue what this line of code does nor how it works

[ -n "$DAEMON_CONF" ] || exit 0

In searching online for bash tutorials, I've never seen anyone do this

When I run the code, my shell window closes (because $DAEMON_CONF is not set to anything). If I change the code to

[ -n "not empty" ] || exit 0

my console window does not close.

so, -n evaluates to true, and or'ed with exit 0, is what?


If the expression in [] returns false, do the thing after the or || (and exit 0). Otherwise, it will short circuit and the next statement will be evaluated.