This is the script I currently have-
#!/bin/bash if["$#" == "2" OR who | grep ":0" == ""] export DISPLAY=:0 xset dpms force on mplayer -fs $1.mp4 fi
It doesn't work.
Thanks for your help.
This is the script I currently have-
#!/bin/bash if["$#" == "2" OR who | grep ":0" == ""] export DISPLAY=:0 xset dpms force on mplayer -fs $1.mp4 fi
It doesn't work.
Thanks for your help.
You should spend some time reading man test
, it looks to me like you've got several problems here:
if [ "$#" = "2" -o -z "$(who | grep ':0')" ]; then
[
.-o
is the OR operator.-z
for testing against the empty string.$(...)
to execute the who command.]
.who
prints out times and grep
is going to match a lot of false positives against HH:MM:SS
. You may want to improve your match.$(who|grep)
, rather than testing for empty string output.In the future, more detail than "it doesn't work" is preferred ;)
In BASH, the test for NULL is -z
, e.g if [ -z "$NAME" ]; then ...
. However, you can just as easily use the exit status from grep instead:
root@tpost-desktop:/usr/src# who | grep :0 tpost tty7 2010-05-23 09:16 (:0) root@tpost-desktop:/usr/src# echo $? 0 root@tpost-desktop:/usr/src# who | grep :123 root@tpost-desktop:/usr/src# echo $? 1
If grep did not find what you asked, it will exit with a non-zero status. So you could do something like:
who | grep :0 >/dev/null 2>&1 if [ $? = 0 ]; then USING_DISPLAY=1 else USING_DISPLAY=0 fi
Then test the value of USING_DISPLAY
, play the movie if its 0
There needs to be a space after the if
, after the [
and before the ']'.
#!/bin/bash if [ "$#" == "2" ] || ! who | grep '(.*:0.*)$' > /dev/null 2>&1 then export DISPLAY=:0 xset dpms force on mplayer -fs $1.mp4 fi