Hi i have one variable like DIR="f1 f2" in config file
in my script i have one runtime variable LFILE="DIR"
now i want to use $DIR in my script by using LFILE that is i dont want to use DIR dirctly i am extracting DIR by some other means.
Config file :
DIR="f1 f2"
Script:
LFILE="DIR"
i want senario like List of files
LISTFILES=${$LFILE}
if any clarity want ask question so that i can reert it back.
You didn't say what shell you are using, but in bash you can use indirect variable referencing like this:
$ cat x
#!/bin/bash
DIR="f1 f2"
LFILE=DIR
LISTFILES=${!LFILE}
echo $LISTFILES
exit 0
$ x
f1 f2
$
P.S. Back to your original example, if your shell does not support the above, you can do it using eval as long as you are sure of what you are eval'ing as eval can be dangerous.
eval forces the shell to evaluate the line twice. First (in this example), it does variable expansion so
"eval LISTFLES=\$$LFILE" is replaced with "LISTFILES=$DIR", THEN the shell executes the line.
$ cat x
#!/bin/ksh
DIR="f1 f2"
LFILE=DIR
eval LISTFILES=\$$LFILE
print $LISTFILES
exit 0
$ x
f1 f2
$