Using eval $(docker-machine env <node>) doesn't work

After creating a container on AWS using docker-machine, my book says you can use the syntax eval $(docker-machine env ) to write the environment variables into the shell. However, the command doesn’t work and I get an error message about faulty syntax (syntax error near unexpected token `(’).

I thought there must be a mistake in the book but I’ve since seen the same command used in examples on other web sites. So I thought either my environment isn’t set up correctly or there’s something I’m not understanding.

I’m using the Linux environment for Windows 10 and using the wsl comand to get into the bash shel

I see if I run the command without the eval, it includes some REM commands that include brackets, so I wonder if the problem is that the command is outputting junk that the shell doesn’t understand.

Actually, if I try to run the REMed code:

@FOR /f “tokens=*” %i IN (’“C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe” env aws-node-1’) DO @%i

it fails with the same error message.

I had half the answer t my own question - the syntax generated by the expression is wrong. That’s because it only works for a particular UNIX shell. It isn’t the right syntax for the BASH shell. I suppose the problem is that you can’t make serialisation environment-aware.

The author of the book I’m using claims to be using the BASH shell, so it’s not clear why he said to use it, and it’s not surprising I was confused.