How can I get the value of the environment variable that is inside a text. I have the script below and assigning the directory value which is a combination of an env variable with some directory but looks like it is not being translated to its actual value I would like to list the contents of the the directory list in dir_file config file
here is my set up:
environment variable
HOME_DIR=/export/home/user1dir_file file has the following lines:
$HOME_DIR/some_directory1
$HOME_DIR/some_directory2
and so on...The script:
#!/usr/bin/ksh
for i in `cat dir_file`
do
echo $i
ls $i
doneoutput:
$HOME_DIR/some_directory1
$HOME_DIR/some_directory1: No such file or directory
$HOME_DIR/some_directory2
$HOME_DIR/some_directory1: No such file or directory
Place eval in front of the ls command. eval forces $i to be interpreted as an argument to ls: while read i do echo $i eval ls $i done < dir_file # end scriptI choose to use a while loop instead of a for loop. Read here to find out why:
Thank you very much Nails! The eval command got the job done, also learned a lot from the link you provided.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |