5

If gpg-agent is executed, it outputs data that can be processed by a shell directly, e.g.:

SSH_AUTH_SOCK=/tmp/ssh-apeOFqMF3292/agent.3292; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3293; export SSH_AGENT_PID;
echo Agent pid 3293;

Why is gpg-agent doing this? I've seen more programs doing it. Did shells in the past not support export var=val? Which shells do not support this alternative shell built-in?

I'm working with bash in Kubuntu.

Lekensteyn
  • 20,830

2 Answers2

12

The traditional Bourne shell didn't support combining them (although the System V one let you omit the ;; the 4.2BSD / SunOS shell didn't). It was added by the Korn shell (crossing the Bourne shell's export with csh's setenv) and subsequently adopted by other shells and by POSIX.2. Many commercial Unixes still ship the System V variant of the Bourne shell as /bin/sh, so retaining compatibility is a good idea for portability.

geekosaur
  • 32,047
0

It doesn’t apply to constant strings, but a reason to get in the habit of doing this as two separate commands is that export FOO=$(mycmd) masks the exit status from mycmd — it will report success even if mycmd fails.  See How is the return status of a variable assignment determined? and the ShellCheck Wiki.