I have some config-file. Config-file contains string: LocalPath /media/$USER
I read config-file in bash-script:
while read var value
do
export "$var"="$value"
done < my-conf-file.conf
So, I can use $LocalPath
in bash-script. It equals: /media/$USER
, but I want to have: /media/user1
(user1 is my user).
How I can implement it?
read
does not expand variables from your config file.You can verify that:
This answer on Stackoverflow gives a solution.
Change your script to this to make it expand variables:
As Kyle Strand suggested in a comment, the easiest solution is to make the config file a Bash script:
Then source it from your main script:
Or if you have a bunch of variables, and don't want to type
export
for every one, make the config file like this: