bash variable substitution
I have a config file (not a script) that states where to find a file named key.dat. With this config, I need to operate on the key.dat, so I did the following...
Code:
$ cat myconfig My question is, how can I make $mypath expanded in the test so that I can get hold of the file key.dat? Thanks. |
I think you don't need to mess around with grep. Just source the file. What is the output of the following?
Code:
. myconfig PS. You say that myconfig is not a script, but from what you post above the syntax is bourne shell compatible, so sourcing it should work. |
Can't. The file is not executable. e.g. 664
and there are other stuff in the file that is not valid command. |
A file doesn't have to be executable in order to source it. Try the suggestion.
|
Right. That is true. Thank you both.
For the sake of learning, if sourcing the file doesn't work, e.g. myconfig does not contain valid bash syntax. Any work around to expand 'variable inside strings'? |
Quote:
Code:
$ echo $mypath |
Thanks. This is what I needed.
Code:
$ KEYF=`eval echo $(grep '^keyfile=' myconfig | cut -d '=' -f 2)` |
All times are GMT -5. The time now is 06:42 PM. |