How to pass varaible from shell to PHP correctly

7 篇文章 0 订阅

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值