[aclug-L] Re: odd shell question
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
exec is like execl(2): it keeps your current process id and most
of the process attributes, but frees your address space, and loads
a new program and its data in its place. exec will fail if, e.g.,
there isn't enough memory available to load the new program, or
if the program can't be found, or isn't executable, or isn't
executable by you, or possibly a few other things, but otherwise
you no longer have a shell to return to.
but you probably already know all that. unfortunately, i don't
know what these programs are supposed to do (which might be
helpful in sorting out the problem).
Jeff wrote:
>
> I have an odd one for y'all. Just when you think you know how
> something should work...
>
> I installed openssl and openssh on this laptop here, and went to
> make things more automated by using ssh-agent and ssh-add. The
> manpage for ssh-agent suggests:
>
> Here's a trick that will allow you to start this up from your
> .bash_profile (just put it in as the first thing that
> happens):
>
> [ ! "$SSH_AGENT_PID" ] && exec ssh-agent -- bash --login
> ssh-add
my ssh-agent(1) man page shows an example that uses eval. if
ssh-agent prints out a line that looks like:
SSH_AGENT_PID=19913; export SSH_AGENT_PID
then substituting eval for exec would simply initialize the
uninitialized SSH_AGENT_PID variable. that way ssh-add always
runs with said variable set.
> The two commands appear to be on one line in the manpage, but I
> assume (!) they're to be two separate lines -- it runs
> (execs) ssh-agent to run bash (--login), which will source
> .bash_profile again, but the test will fail the 2nd time around,
> running ssh-add after the environment variables are set (which is
> correct). Additionally, bash complains if you try to run it
> like: "bash ssh-add": "ssh-add: /usr/local/bin/ssh-add: cannot
> execute binary file". (since ssh-add isn't a shell script).
good for bash.
> The problem with the manpage's suggestion is: on login, bash gets
> to the 'exec' line and hangs (it runs ssh-agent -- bash --login),
> but I never get a prompt back.
that's what exec does. if exec doesn't fail, your shell is gone.
login should run when ssh-agent exits.
> If I change .bash_profile to simply /run/ ssh-agent, it works just
> fine (but I end up with a SHLVL of 2 & having to exit twice,
> provoking future momentary confusement).
>
> If I run 'exec ssh-agent -- bash' from the commandline, it works
> just fine, giving me a prompt back. Same with "exec ssh-agent --
> bash --login".
>
> It breaks if I put it in .bash_profile, however.
>
> I put 'set -x' at the top of .bash_profile to watch what happens,
> and it's executed just like I think it should be; it's just that
> it hits the 'exec ssh-agent...' line and I never see bash again.
again, this is correct. your shell can't trace anything after the
exec, because it doesn't exist any more.
> Anyone seen anything like this? The system is a 'install
> everything because I'm tired of fighting with you' Mandrake 6.1,
> which I'm not intimately familiar with, but was the easiest choice
> at the time.
>
> Thanks :)
>
> -jeff
> --
> default, n.: [Possibly from Black English "De fault wid dis system is you,
> mon."] The vain attempt to avoid errors by inactivity. "Nothing will
> come of nothing: speak again." -- King Lear. -- Stan Kelly-Bootle
--
/*
* Tom Hull * thull@xxxxxxxxxxx * http://www.ocston.org/~thull/
*/
- [aclug-L] Re: odd shell question,
Tom Hull <=
|
|