|
Home > Archive > Unix Shell > November 2005 > Where to set up BASH_ENV?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Where to set up BASH_ENV?
|
|
| paulaugust2003@yahoo.com 2005-11-28, 2:52 am |
| Hi,
I am confused about setting up the environment variable BASH_ENV. What
I want to achieve is that I can run a command in a remote machine in
the following way:
ssh username@remotemachine "some; commands;"
However, it doesn't work because the commands I want to run remotely
may contain aliases and other definitions that are only available if I
login the remote machine interactively. Okay, since bash is my shell, I
try the following way:
ssh username@remotemachine "bash -c 'some; commands;'"
But it still doesn't work. I checked bash manual and suspect that it is
an issue related to non-login, non-interactive shell. The manual says
that in this case, the bash shell will source a file specified in
BASH_ENV. Thus if BASH_ENV points to my ~/.bashrc file, the problem
would,be solved. I tested BASH_ENV value by the following command
ssh username@remotemachine "echo $BASH_ENV"
and unfortunately it gives me empty string. It seems that BASH_ENV is
not set up in the remote machine. The bash manual does not say where to
set up BASH_ENV. I searched internet and found a few discussions about
setting up BASH_ENV. They all indicate that BASH_ENV can be set up in
~/.bash_profile. But bash manual says that ~/.bash_profile will be read
only when a shell is a login shell. I tried it anyway and it is indeed
not working even if I use the following way
ssh username@remotemachine "bash -c -l 'some; commands;'"
Do you know where to set up BASH_ENV? Thanks a lot for any help.
Paul.
| |
| Chris F.A. Johnson 2005-11-28, 2:52 am |
| On 2005-11-28, paulaugust2003@yahoo.com wrote:
> Hi,
>
> I am confused about setting up the environment variable BASH_ENV. What
> I want to achieve is that I can run a command in a remote machine in
> the following way:
>
> ssh username@remotemachine "some; commands;"
>
> However, it doesn't work because the commands I want to run remotely
> may contain aliases and other definitions that are only available if I
> login the remote machine interactively. Okay, since bash is my shell, I
> try the following way:
>
> ssh username@remotemachine "bash -c 'some; commands;'"
Pipe your commands to ssh:
printf "%s\n" ". ~/.bashrc" alias | ssh username@remotemachine
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Hubble 2005-11-28, 7:50 am |
| What about using
ssh username@remotemachine "bash -i -c 'some; commands;'"
Hubble.
| |
| paulaugust2003@yahoo.com 2005-11-28, 6:04 pm |
| Many thanks to Hubble and Chris for your kind help. Chris' method
produces an error message; "Pseudo-terminal will not be allocated
because stdin is not a terminal." But Hubble's method works as I
expected. I should kick myself for not trying -i before posting my
question here.
The only minor problem with Hubble's method is that it can't find a
command defined in a bin directory under my home directory. Of course,
I can easily get around this problem by issuing ~/bin/command, instead
of command only. I need to figure out why the correct path was not
specified in this way. Also I am curious where the variable BASH_ENV
should be set.
Thank you again.
Paul.
| |
| Chris F.A. Johnson 2005-11-28, 6:04 pm |
| On 2005-11-28, paulaugust2003@yahoo.com wrote:
> Many thanks to Hubble and Chris for your kind help. Chris' method
> produces an error message; "Pseudo-terminal will not be allocated
> because stdin is not a terminal."
That is an informational message (or, at most, a warning), and the
commands will run as expected.
> But Hubble's method works as I expected. I should kick myself for
> not trying -i before posting my question here.
Please read: <http://cfaj.freeshell.org/google>
> The only minor problem with Hubble's method is that it can't find a
> command defined in a bin directory under my home directory. Of course,
> I can easily get around this problem by issuing ~/bin/command, instead
> of command only. I need to figure out why the correct path was not
> specified in this way.
You probably want --login rather than -i. Or you can explicitly
source whatever scripts you need.
> Also I am curious where the variable BASH_ENV should be set.
Before bash is invoked, otherwise it will have no effect.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
|
|
|
|
|