Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positional Parameters in C-shell

Tags:

linux

shell

csh

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.

like image 352
Jeetesh Avatar asked Jun 03 '26 11:06

Jeetesh


1 Answers

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.

like image 62
MichalH Avatar answered Jun 06 '26 00:06

MichalH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!