Positional parameters in the C-shell

I can not print the positional parameters using this shell command: echo $1

.

I use it like the following two commands:

% set hi how are you
% echo $1

      

Nothing will come out of the command, but hi

should be printed.

+3


source to share


1 answer


In csh, you need to assign an array argv

:

> set argv=(hi how are you)
> echo $1
hi

      

Explanation:



argv

is an array variable that contains a list of command line arguments (the 0th argument is the name when invoking the shell, and the other is from the 1st index). Variables $0

- $n

also contain the values โ€‹โ€‹of the arguments. So it $argv[1]

matches $1

. To assign an array variable, you can use either set arr=(value1 value2)

or set arr[1] = value1

.

set value1 value2

will work in bash

, but csh

should be similar to C, so an array is used argv

(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 (zero) value to the variables first

and second

.

+1


source







All Articles