QUERY IN BRIEF
Listing the query in short
#! /bin/csh -f
#say i have invoked the script with two arguments : a1 and 2
set arg = $1 # that means arg = a1
echo "$arg" #it prints a1
#now what i want is:
echo "$a1"
#it will give error message :a1 undefined.
#however what i need is that the echo statement with a1 should print 2 (=$2)
QUERY IN DETAIL
consider the script code below
script name: dyn_par
#!/bin/csh -f
awk '{for(i=1;i<=NF;i++)printf("%s=%s\n",$i,$i)}' script_name.txt
#the awk line reads the script and prints
#script1=script1
#a1=a1
#
while ( $1 != "" )
set arg = $1 #That is arg = a1
echo " arg ==== $arg "
shift
# I need to have a1 = $1
echo "a1 = $a1" # should print value at $2
shift
end
content of script_name.txt is
script1 a1
at terminal, the script is invoked as below:
$ ./dyn_par a1 2
What i am trying to do is, to create the variable "a1" dynamically and assigning it a value a1= $2 =(which is here 2).
Rather than directly declaring the variable in dyn_par script, i wish to
1) dynamically declare variables using the data in script_name.txt file (so that any entries made to script_name file will automatically declare the variables)
2) use arguments ,($1) to identify the variable a1 and $2 to store the value(=2 here) to it.