ssh eval "$(ssh-agent -s) returns Illegal variable name
Asked Answered
C

3

6

Why does the eval statement return

Illegal variable name

$ eval "$(ssh-agent -s)"
Illegal variable name.
Croydon answered 24/10, 2014 at 2:43 Comment(0)
H
11

Try $ eval "ssh-agent" instead.

Hattie answered 8/1, 2015 at 14:44 Comment(0)
B
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.

Beta answered 1/11, 2015 at 20:9 Comment(1)
This also gives "Illegal variable name." for meCovered
H
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

Hygrostat answered 5/2, 2022 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.