What [-n "$ VARIABLE"] || output 0 means

Looking for a fix for the problem in /etc/init.d/hostapd on Debian. However, I do not know what this line of code does and how it works.

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

In an online search for bash tutorials I never saw anyone do this

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

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

my console window does not close.

therefore, -n evaluates to true and or'ed with output 0, what?

+4
source share
3 answers

[] false, || ( exit 0). , .

+4

[ - test. /, man-:

man test

-n:

-n STRING

          the length of STRING is nonzero

Furthemore || OR. , test False, || . test true, .

: " $DAEMON_CONF , 0"

:

if test ! -n "$DAEMON_CONF"; then
    exit 0
fi
+3
[ -n "$DAEMON_CONF" ] || exit 0

. :

[ -z "$DAEMON_CONF" ] && exit 0

- :

[ "$DAEMON_CONF" ] || exit 0
+2

All Articles