在 tcshell 中传递部分参数
我正在编写一个 shell 脚本 (tcsh),它应该接收 3 个或更多参数。前 3 个将传递给一个程序,其余的应该传递给另一个程序。总而言之,脚本应该类似于:
./first_program $1 $2 $3
./second program [fourth or more]
问题是我不知道如何执行后者 - 传递第三个之后的所有参数。
I'm writing a shell script (tcsh) that is supposed to received 3 parameters or more. The first 3 are to be passed to a program, and the rest are supposed to be passed to another program. All in all the script should look something like:
./first_program $1 $2 $3
./second program [fourth or more]
The problem is that I don't know how to do the latter - pass all parameters that are after the third.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我向您介绍
shift
命令:例子:
I present to you the
shift
command:Example:
您可以按如下方式使用
shift
:$*
将包含其余参数。在执行
shift
之前,您还必须通过检查$#argv
并确保其非零来进行错误检查。或者,您可以检查脚本开头处的$#argv
值,并确保它至少为3
。You can make use of
shift
as follows:$*
will contain the remaining parameters.You must also do error checking before you do a
shift
by checking$#argv
and ensuring it is non-zero. Alternatively you can check the value of$#argv
at the star of the script and ensure that it is atleast3
.