PDA

View Full Version : Bash script question


spetsacdc
04-24-2009, 01:33 AM
Hi, I have a bash script that calls a php script...


#!/bin/bash
if [ ( php.exe testing.php ) == "1" ]
then
/cygdrive/c/WINDOWS/explorer.exe /e,`cygpath -w -a "open.png"` &
fi

my testing.php file checks something online and echo's a 0 or a 1. How do I use this output value in my bash script as part of the conditional check? The above does not work, and trying something like:

$number = php.exe testing.php

does not store a 0 or 1 in number.

Any tips?

Thanks

bdl
04-24-2009, 01:58 AM
Hmm. I'm not sure if the PHP executable will actually process the script without having to have an argument, i.e. -f. The second thing I would look at is referencing the PHP executable with its full path,e.g. C:\php\php.exe.

PHP command line options (http://us.php.net/features.commandline)

spetsacdc
04-24-2009, 02:19 AM
Thanks for the help.

I've tested

php.exe testing.php

On a line by itself it runs the testing.php code correctly and I get the output of 1 or 0. I just don't know how to store that output as a variable in my bash script.

oesxyl
04-24-2009, 02:49 AM
Thanks for the help.

I've tested

php.exe testing.php

On a line by itself it runs the testing.php code correctly and I get the output of 1 or 0. I just don't know how to store that output as a variable in my bash script.
you are on windows system? in this case first line, shbang, is useless.
I don't know how bash work on windows but try this:

number=`php.exe testing.php`;
if [ "$number" == "1" ]; then
# your code here
fi

put full path for php.exe and don't put whitespaces between number, = and rest.

best regards

bdl
04-24-2009, 03:00 AM
Oh! Excellent point, oesxyl. It's been awhile since I've done any bash scripting, and using the `backticks` will capture the output of `whatever`.

spetsacdc
04-24-2009, 03:10 AM
you are on windows system? in this case first line, shbang, is useless.
I don't know how bash work on windows but try this:

number=`php.exe testing.php`;
if [ "$number" == "1" ]; then
# your code here
fi

put full path for php.exe and don't put whitespaces between number, = and rest.

best regards

Thanks! It's working great.

oesxyl
04-24-2009, 03:13 AM
Oh! Excellent point, oesxyl. It's been awhile since I've done any bash scripting, and using the `backticks` will capture the output of `whatever`.
the question is if will work on windows, :)
I talk about bash on windows in general, not only backticks.

best regards

spetsacdc
04-24-2009, 03:16 AM
Ya, I don't really like how I had to install a ton of different stuff to get it to work (vim, cygwin, nnCron). However, I don't have time to switch to linux right now. I didn't need this project to be pretty, but just work. Now, every 1 minute my program checks if a class I want to take at school has been opened. If it is, I get a ghetto pop-up.

oesxyl
04-24-2009, 03:24 AM
Ya, I don't really like how I had to install a ton of different stuff to get it to work (vim, cygwin, nnCron). However, I don't have time to switch to linux right now. I didn't need this project to be pretty, but just work. Now, every 1 minute my program checks if a class I want to take at school has been opened. If it is, I get a ghetto pop-up.
the problem is how it work because you can waste a lot of time trying to fix some weird things.
Many years ago I use djgpp on a win 95/98, almost full *nix enviroment but was painfull.

best regards