I have been reading about how ssh-agent works and how it relates to the shell environment. I understand why we do eval ssh-agent now (usually in /etc/profile), it makes logical sense. However the output of ssh-agent seems a little unnatural to me

# The bad way just (env dont get set, just printed) so i can see its output
[matt@laparchie rc.d]$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-EQUsXLxh4103/agent.4103; export SSH_AUTH_SOCK;
echo Agent pid 4104;

Why doesnt ssh-agent just output

export SSH_AUTH_SOCK=/tmp/ssh-EQUsXLxh4103/agent.4103;
export SSH_AGENT_PID=4104;
echo Agent pid 4104;

When pumped to eval both do the same (i.e. setting env variables), but the latter is less verbose and more clear to me, is it just a style (the verbosity of the first)? and if so does the style have a history/reason? or is there something technically different?

  • BASH is not the only shell. People using other shells want to use SSH too. – Zoredache Sep 15 '11 at 4:44

What ssh-agent outputs is sh syntax. The export varname=value construct is valid in bash but is not recognized by many implementations of sh whereas the varname=value; export varname construct is.


Technically, X=Y; export X is the right way.

But because it's unnecessary verbose, bash (as well as sh and zsh) provides shortcut export X=Y, which does exactly the same.

Actually, I don't know any shell, which uses export X to set environment variables, but does not understand export X=Y, but still using more verbose way is considered more portable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.