What does [] do in bash?

Possible duplicate:
bash: double or single bracket, parentheses, braces

Looking at the rc.dcron script in archlinux:

#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions

name=crond
. /etc/conf.d/crond
PID=$(pidof -o %PPID /usr/sbin/crond)

case "$1" in
start)
    stat_busy "Starting $name daemon"
    [[ -z "$PID" ]] && /usr/sbin/crond $CRONDARGS &>/dev/null \
    && { add_daemon $name; stat_done; } \
    || { stat_fail; exit 1; }
    ;;

So far I can understand most of the syntax that this does:

 [[ -z "$PID" ]]

I saw it also like:

 [ -z "$PID" ]

In the link, I found what is []used in the if-statement, but here I do not see this. Any help is much appreciated. Thank!

+5
source share
3 answers

([) , 0 true - false. "If" . , . ([[) bash .

+6

/usr/bin/test, Unix. , , , . , Bash.

http://tldp.org/LDP/abs/html/testconstructs.html#DBLBRACKETS

, [( ). test . , (0 true, 1 false).

2.02 Bash [[...]], , . , [[ , .

[[]], .

[[...]] [...] . , &, ||, < > [[]], , [].

+4

this :

: [[]]

[[]]

0 1 . [[' and]] '; , , , , .

& & || expression2, 1 .

0

All Articles