Hi all, I have a requirement where I am taking the first argument as argument name and storing the second argument in argument name as value.
Thanks to ppl here, i learnt to do it.
while ( $1 != "" )
set arg = $1
shift
set val = "$1"
echo "set $arg=$val" > temp_file && source temp_file
shift
end
Now,the format of my argument has changed, which is instead of argument name (say "./script arg1 1"), I am taking "./script -arg1 1",
I still need to save the "1" value in arg1, which is generated once i give "-arg1" as an argument.
is there anyway i can directly generate "arg1" instead of "-arg1" as my variable?
Please advice.
I found a partial solution
while ( $1 != "" )
set arg = "`echo $1 | sed '/-/s// /g'`"
echo $arg
shift
set val = "$1"
echo "set $arg = $val" > temp_file && source temp_file
shift
end
but still I am getting an error:
me@linux: csh -x ./test -a 1 -b 2
while ( -a != )
set arg = `echo -a | sed '/-/s// /g'`
echo -a
sed /-/s// /g
echo a
a
shift
set val = 1
echo ------------------------------------------------------arg == a
------------------------------------------------------arg == a
echo ------------------------------------------------------val == 1
------------------------------------------------------val == 1
echo set a = 1
source temp_file
set a = 1
shift
echo you created parameter ( a ) with value ( 1 )
you created parameter ( a ) with value ( 1 )
end
while ( -b != )
while: Missing file name.
---------- Post updated at 02:59 PM ---------- Previous update was at 02:53 PM ----------
Hey birei
I am afraid your syntax is not working.
I am scripting in c shell, i guess it is not supported by csh.
---------- Post updated at 03:40 PM ---------- Previous update was at 02:59 PM ----------
This is the solution
while ( "$1" != "" )
set arg = "`echo $1 | sed '/-/s// /g'`"
echo $arg
shift
set val = "$1"
echo "set $arg = $val" > temp_file && source temp_file
shift
end