Because a number of my vars have spaces or special characters in them, I 
have to do this nonsense because env output doesn't quote the values.

ONE=1
TWO="2 2"
THREE="3 -3 +3 =3"
EXPORT_VARS="ONE TWO THREE"

echo $(for VAR in $EXPORT_VARS ; do echo "${VAR}=\"${!VAR}\"" ; done) | 
tr '\n' ' '

Which is a good example of bash indirect parameter expansion.


So, the line below turns into this:

tmux new-session "env $(echo $(for VAR in $EXPORT_VARS ; do echo 
"${VAR}=\"${!VAR}\"" ; done) | tr '\n' ' ') bash"

And ugly as it is, it works for me.  I don't like it though.  I'd much 
rather have a tmux option like this:

tmux new-session -setenv "$EXPORT_VARS" "bash"



On 6/1/14, 2:43, Balazs Kezes wrote:
> On 2014-05-31 20:59 -0700, Jesse Molina wrote:
>> This first bash script has a number of environmental variables which I
>> need to exist in the new-session env to get passed on to the
>> application/script in which the new session starts.
> You can try passing the current environment to the session's first
> process on its command line. Try this (beware: this is a bit unsafe this
> way, you'll need to sanitize this command, this is just a
> demonstration):
>
>       tmux new-session "env $(env | tr '\n' ' ') bash"
>
> After the new session already exists, you can script around the
> set-environment command in tmux.
>


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to