Escape special shell characters when using os.Getenv

1,173 views
Skip to first unread message

weiten...@gmail.com

unread,
Sep 19, 2016, 12:38:12 PM9/19/16
to golang-nuts
I tried to `escape` dollar sign when using os.Getenv; 
I found that golang doesn’t do exactly what I expect (for example `$$var_one` —> print `$var_one`). 
Any suggestion?
my temporary solution requires copying code from golang os pkg https://play.golang.org/p/nnsK9llwvr

Matt Harden

unread,
Sep 25, 2016, 6:53:29 PM9/25/16
to weiten...@gmail.com, golang-nuts
There is no escaping mechanism built in to os.Expand.

One workaround would be to define an environment variable containing a dollar sign: https://play.golang.org/p/InJx2_EWB2
Another is to substitute an unused character or string and replace it after expansion: https://play.golang.org/p/j8Oa3dgdoH



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

Matt Harden

unread,
Sep 25, 2016, 6:55:06 PM9/25/16
to weiten...@gmail.com, golang-nuts
Reply all
Reply to author
Forward
0 new messages