Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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;
SSH_AGENT_PID=4104; export SSH_AGENT_PID;
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?

share|improve this question
    
BASH is not the only shell. People using other shells want to use SSH too. –  Zoredache Sep 15 '11 at 4:44
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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