How to use environment variables in each session

280 views
Skip to first unread message

jlm17

unread,
Sep 18, 2012, 10:15:28 AM9/18/12
to parall...@googlegroups.com
I'm probably doing something obviously wrong, but when I try to set an environment variable, it does not take:

[root@host1 ~]# pssh -P -v -p 1 -H "host1 host2" "export foo=\"hi\"; echo \"<$foo>\""
host1: <>
[1] 09:59:35 [SUCCESS] host1
host2: <>
[2] 09:59:36 [SUCCESS] host2

But:

[root@host1 ~]# export foo="hi"; echo "<$foo>"
<hi>

This should be Bash, as that is what is printed when I use "echo $SHELL." I'm logging into CentOS machines.

Thanks for any help you can provide. Oh, I'm running pssh 2.3.

Andrew McNabb

unread,
Sep 18, 2012, 12:38:23 PM9/18/12
to parall...@googlegroups.com
On Tue, Sep 18, 2012 at 07:15:28AM -0700, jlm17 wrote:
> I'm probably doing something obviously wrong, but when I try to set an
> environment variable, it does not take:
>
> [root@host1 ~]# pssh -P -v -p 1 -H "host1 host2" "export foo=\"hi\"; echo
> \"<$foo>\""
> host1: <>
> [1] 09:59:35 [SUCCESS] host1
> host2: <>
> [2] 09:59:36 [SUCCESS] host2

The $foo is actually getting substituted by Bash on your local machine
before pssh even runs. Since the variable isn't defined, $foo gets
expanded to the empty string. The solution is to tell Bash not to
expand $foo by either:

1) Using single quotes:
[root@host1 ~]# pssh -P -v -p 1 -H "host1 host2" 'export foo=\"hi\"; echo
\"<$foo>\"'

2) Escaping the $:
[root@host1 ~]# pssh -P -v -p 1 -H "host1 host2" "export foo=\"hi\"; echo
\"<\$foo>\""

This sort of problem can be really "fun" sometimes.

--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868

jlm17

unread,
Sep 18, 2012, 1:27:03 PM9/18/12
to parall...@googlegroups.com
Of course! At least I was right; I was doing something obviously wrong.

Thanks a bunch.
Reply all
Reply to author
Forward
0 new messages