ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Im reading values from a file line by line.
Sample File
..
first|blah
second|$some_shell_var
...
I have to process these values like
...
source=$(echo $line | cut -d'|' -f1)
dest=$(echo $line | cut -d'|' -f2)
echo $source
echo $dest
...
When I echo the values I get 'blah' for the first line(first|blah).
For the second line I get '$some_shell_var'. But instead I want the variable value to be expanded(I mean I want the $some_shell_var to be substituted with its value). How this can be done in BASH?
#check if dest starts with a '$'
if [ ${dest:0:1} = '$' ] ; then
#remove the '$'
dest="${dest:1}"
#{!dest} uses indirection,
#search for variable indirection in the bash man page for details
echo "source = $source, dest = ${!dest}"
else
echo "source = $source, dest = $dest"
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.