shell - Assign BASH variable from file with specific criteria -


a config file last line contains data want assign right of = sign variable can display , call later in script.

example: /path/to/magic.conf:

foo bar thisoption=foo.bar.address:location.555 

what best method in bash shell script read last line of file , assign right of equal sign? in case, foo.bar.address:location.555.

the last line has want target , there ever single = sign in file happens last line.

google , searching here yielded many close non-relative results using sed/awk couldn't come i'm looking for.

use sed:

variable=$(sed -n 's/^thisoption=//p' /path/to/magic.conf) echo "the option is: $variable") 

this works finding , removing thisoption= marker @ start of line, , printing result.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -