Search code examples
dockerfish

fish shell pass argument from command


I'm trying to use fish with docker machine with docker client in fish shell. I can run docker-machine config dev and it would give me the parameters to pass to docker. But when I tried to do that docker (docker-machine config dev) ps it would say flag provided but not defined: --tls --tlscacert

If I switch my shell to bash then docker $(docker-machine config dev) ps works fine. So what's wrong with the syntax here?

I tried googling for the answer, seems like that error is related to Go, maybe?

Docker version 1.5.0, build a8a31ef

fish, version 2.1.1

EDIT: Here is the output of docker-machine config dev

--tls --tlscacert=/Users/me/.docker/machine/machines/dev/ca.pem --tlscert=/Users/me/.docker/machine/machines/dev/cert.pem --tlskey=/Users/me/.docker/machine/machines/dev/key.pem -H="tcp://192.168.99.102:2376"


Solution

  • You are running into this issue.

    The short answer is that bash will further split command substitutions into separate arguments on any whitespace, while fish splits them only with newlines. Since docker-machine config dev doesn't output newlines, the outer docker command just gets one giant argument, with embedded spaces.

    To simulate the bash behavior, you can replace spaces with newlines:

    docker (docker-machine config dev | tr -s ' ' \n) ps
    

    That should do what you expect.