6

Why does the eval statement return

Illegal variable name

$ eval "$(ssh-agent -s)"
Illegal variable name.
baao
  • 71,625
  • 17
  • 143
  • 203
gkmohit
  • 690
  • 2
  • 12
  • 28

3 Answers3

10

Try $ eval "ssh-agent" instead.

Zoë Clark
  • 1,334
  • 2
  • 13
  • 25
3

The correct command is

eval $(ssh-agent)

(no quotes!)

Background: ssh-agent sends two lines of code to stdout

SSH_AUTH_SOCK=/tmp/ssh-xxxxxxxxx/agent.nnnn; export SSH_AUTH_SOCK;
SSH_AGENT_PID=22414; export SSH_AGENT_PID;

where /tmp/ssh-xxxxxxxx/agent.nnnn is a file used as a socket to connect to the agent, and the second line contains the PID of the agent process.

$(command) contains those two lines and eval takes them and uses them to create/execute two commands
- result: you have two environment variables telling every process how to connect to the agent.

guntbert
  • 536
  • 6
  • 19
1

In .csh or .tcsh, the syntax to insert the results of a command into another command like eval is backquote, so the necessary command seems to be

eval `ssh-agent`

That sets the two environment variables and prints the agent PID rather than giving an "Illegal variable name" error