Possible Duplicate:
bash: double or single bracket, parentheses, curly braces
Looking at the rc.d cron 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; }
;;
While I can figure out most of the syntax, what the heck does this do:
[[ -z "$PID" ]]
I saw that also written as:
[ -z "$PID" ]
In reference I found that [] is used in if-statements, but I see none here. Any help is much appreciated. Thanks!
The opening bracket ([) is an alias for the test command which performs all the tests and returns 0 for true or something else for false. The “if” reacts only to the return value of the test command. The closing bracket tells test where the expression ends. The double brackets ([[) are a bash built in and can replace the external call to test.