参数的传入

hjd1399 2006-11-15 03:10:25
在SHEE脚本中有以下的命令:
/xxx/php xxx.php

想在SOLARIS命令行中执行SHELL,然后向PHP程序传递参数.但是参数也要在SOLARIS命令行中输入.请问大人们怎么去实现这个功能.在SHELL中写如参数的方法知道,就是在命令/xxx/php xxx.php 的后边写如参数,有几个就写几个.但是从SOLARIS的命令行传递参数的方法不知道.请高人指点.
...全文
233 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
asphp 2006-11-21
  • 打赏
  • 举报
回复
shift 就可以了
wuxier 2006-11-16
  • 打赏
  • 举报
回复
shift
hjd1399 2006-11-16
  • 打赏
  • 举报
回复
thanks for your answer!
还有几个问题请教.
首先我不知道从命令行输入参数的个数.也就是说参数的个数是变化的.
再者,比如从命令行输入参数 ocor>:./myshellscript arg1 arg2 arg3 arg4
我现在只想让arg1 arg2 arg3 arg4作为参数传给PHP,不想把xxx.php 也传给PHP作为一个参数.
现在的情况是系统把xxx.php 作为第一个参数了.而我的目的是想把arg1作为第一个参数.该怎么处理呢??/ 谢谢指教.


ocor 2006-11-15
  • 打赏
  • 举报
回复
i do not understand your questions very clearly. i will answer your questions based on my own understanding.

For example, the shell script name is myshellscript, i assume you use C/TC shell.
on command line
ocor>:./myshellscript arg1 arg2 arg3 arg4
Then in your script, you can use the following statements to set arg1, arg2... as the arguments of your php program.
/xxx/php xxx.php $1 $2 $3 # the $1 is the first arg, $2 is the 2nd and so on, $0 is the script name. you can use echo $0 $1 $2 $3 to output the arg

you can download the "UNIX® Shells by Example Fourth Edition" ebook which is very good for shell programming beginner.

1,543

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 Solaris
社区管理员
  • Solaris
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧