Passing partial arguments in tcshell
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 progr开发者_开发问答am [fourth or more]
The problem is that I don't know how to do the latter - pass all parameters that are after the third.
I present to you the shift command:
shift[variable]
Without arguments, discardsargv[1]and shifts the members ofargvto the left.
Example:
$ 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
You can make use of shift as follows:
./first_program $1 $2 $3
shift # shift 3 times to remove the first 3 parameters.
shift
shift
./second program $*
$* 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 atleast 3.
加载中,请稍侯......
精彩评论