I am unable to print positional parameters using this shell command: echo $1
.
I am using it as following two commands:
% set hi how are you
% echo $1
Nothing get out of the command, but hi
should be print.
In csh, you need to assign to the argv
array:
> set argv=(hi how are you)
> echo $1
hi
Explanation:
argv
is an array variable which contains the command line argument list (the 0th argument is name as the shell was invoked and the other start from 1th index). Variables $0
- $n
also contain values of the arguments . So $argv[1]
is the same as $1
. To assign to an array variable, you can use either set arr=(value1 value2)
or set arr[1] = value1
.
set value1 value2
would work in bash
, but csh
is meant to be similar to the C language, therefore the argv
array is used (read a little about C program command line arguments if you don't know why).
But in csh
, this: set first second
means assigning an empty (null) value to the variables first
and second
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.