What does ‘[‘ ‘]’ indicate in this output?
$ bash -ex ~/bin/client_services
+ : starting daemons reqd. for clients
++ ps aux
++ grep -q memcached
+ '[' ']'
My source file is:
if [ `ps aux | grep -q memcached` ]; then
echo 'Memcached exists'
fi
2
Answers
What you’re saying here is the output of the debugging
-x
flag for bash. First it has to run theps aux
, then it has to run thegrep ...
. Then it has to test the results. The[...]
test syntax is an expression in itself, and also has to be evaluated.The
+ '[' ']'
is the representation of that test being performed, shown to you bybash -x
.It means
ps aux | grep -q memcached
expanded to an empty string.If it didn’t you’d get what it expanded to.
E.g.,
ps aux | grep -q memcached
prints