How to pass varaible from shell to PHP correctly

Sometimes, if you want to want to pass the whole "sentence" whcih with blank from shell script to another script which need to deal with the passed value, you will find that, the words has been exploded.

#!/bin/csh
php test $argv

 
it's called  "testshell",  test is another script, and if you run it  under console like this

./testshell "abc 123" "patrick 124"

In test script , if you print or dup  the passed value.Normally,It should get arg(1)= "adc 123"  arg(2)="patrick 124" in  "test" script.But unluckly, the value are as below. arg(1)=abc arg(2)=123  arg(3)=patrick arg(4)=124.  So this is a very hardest thing.  And how to reslove this? Please refer to below, you just refer to http://www.staff.tugraz.at/reinfried.o.peter/unix/cshell.html, then you wiil get the answer. The solution are like this

#!/bin/csh
php test $argv:q

Now, everybody is happy, you can get the whole sentence if you quote it.

One of my friend want to use my shell to be SH, so this have to be updated as below

#!/bin/sh
php test "$@"

then you can get the space string directly

More detail, please refer to below

http://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_13_04

http://www.grymoire.com/Unix/Sh.html

猜你喜欢

转载自wuchengyi.iteye.com/blog/2123565