Expanding environment variables with sed

12 views
Skip to first unread message

tobyt...@gmail.com

unread,
Oct 9, 2015, 8:56:34 AM10/9/15
to Bash One-liners
I am trying to write a sed command to replace tokens in a file with values from environment variables like so:

export my_var=foo
echo "something {{my_var}} bar" | sed -r "s/\{\{(.*?)\}\}/$\1/g"
I want to grab the name of the token (my_var in this case) and then substitute in the value of the environment variable with the same name.

Is this possible? Current the above prints something $my_var bar rather than something foo bar which is what I want.

I'm open to using another tool such awk instead if it's not possible with sed.

Janos Gyerik

unread,
Oct 9, 2015, 9:03:40 AM10/9/15
to bashon...@googlegroups.com
Perhaps you could post your question on Stack Overflow or Unix SE. Once you have your one-liner working well, it will be cool on bashoneliners.com


--
You received this message because you are subscribed to the Google Groups "Bash One-liners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bashoneliner...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages