bash - iterate over lines in file and expand global variables -
i'm trying write bash script iterate on lines in file , expland global variables @ same time.
i have global variable $source_code_dir defined in bashrc file. lets $source_code_dir == /path/to/source/
my external file looks this:
$source_code_dir/some/dir/file.txt $source_code_dir/some/dir/file.cpp and bash script far is:
while ifs=$'\n' read line echo $line done < /path/to/external/file/above.txt the variable $source_code_dir being used in other places in script, accessible , defined correctly;
the output of script
$source_code_dir/some/dir/file.txt $source_code_dir/some/dir/file.cpp and not
/path/to/source/some/dir/file.txt /path/to/source/some/dir/file.cpp can me expand $source_code_dir variable can use it?
one option use eval:
while ifs=$'\n' read line eval echo $line done < /path/to/external/file/above.txt
Comments
Post a Comment