Unix 在tcshell中传递部分参数

Unix 在tcshell中传递部分参数,unix,parameters,shell,tcsh,Unix,Parameters,Shell,Tcsh,我正在编写一个shell脚本(tcsh),它应该接收3个或更多参数。前3个将被传递给一个程序,其余的将被传递给另一个程序。总而言之,脚本应该类似于: ./first_program $1 $2 $3 ./second program [fourth or more] 问题是,我不知道如何执行后一种操作-传递第三个之后的所有参数。我向您展示了shift命令: shift[变量] 如果没有参数,则丢弃argv[1],并将argv的成员向左移动 例如: $ cat /tmp/tcsh.sh #!/b

我正在编写一个shell脚本(tcsh),它应该接收3个或更多参数。前3个将被传递给一个程序,其余的将被传递给另一个程序。总而言之,脚本应该类似于:

./first_program $1 $2 $3
./second program [fourth or more]

问题是,我不知道如何执行后一种操作-传递第三个之后的所有参数。

我向您展示了
shift
命令:

shift
[变量]
如果没有参数,则丢弃
argv[1]
,并将
argv
的成员向左移动

例如:

$ cat /tmp/tcsh.sh
#!/bin/tcsh

echo "$1" "$2" "$3"
shift
shift
shift
echo "$*"
$ /tmp/tcsh.sh 1 2 3 4 5 6
1 2 3
4 5 6

我向您演示
shift
命令:

shift
[变量]
如果没有参数,则丢弃
argv[1]
,并将
argv
的成员向左移动

例如:

$ cat /tmp/tcsh.sh
#!/bin/tcsh

echo "$1" "$2" "$3"
shift
shift
shift
echo "$*"
$ /tmp/tcsh.sh 1 2 3 4 5 6
1 2 3
4 5 6

您可以按如下方式使用
shift

./first_program $1 $2 $3

shift # shift 3 times to remove the first 3 parameters.
shift
shift

./second program $* 
$*
将包含其余参数


在执行
shift
之前,还必须通过检查
$#argv
并确保其非零来执行错误检查。或者,您可以在脚本的星形处检查
$#argv
的值,并确保它至少为
3

,您可以使用
shift
,如下所示:

./first_program $1 $2 $3

shift # shift 3 times to remove the first 3 parameters.
shift
shift

./second program $* 
$*
将包含其余参数

在执行
shift
之前,还必须通过检查
$#argv
并确保其非零来执行错误检查。或者,您可以在脚本的星形处检查
$#argv
的值,并确保它至少为
3