1

I want to override the docker command so that when I do docker ps or docker service ls exactly it will render in the format I want.

I started with this

docker() {
  if [ "$*" == 'ps' ]
  then
    command docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
  else
    eval "command docker $*"
    # eval "command docker $@"
    # command docker $*
    # command docker $@
    # command docker "$*"
  fi
}

However when I did it this does not work

docker service ls --format="table {{.Name}}\t{{.Image}}\t{{.Replicas}}\t{{.Ports}}"

But

command docker service ls --format="table {{.Name}}\t{{.Image}}\t{{.Replicas}}\t{{.Ports}}"

It appears to be because of the " characters being processed.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

1 Answers1

5

Use "$@" rather than $* to ensure that arguments are re-quoted.

docker() {
  if [ "$*" = 'ps' ]
  then
    command docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
  else
    command docker "$@"
  fi
}
Barmar
  • 741,623
  • 53
  • 500
  • 612