Hello all, I wan to create an alias of this command: alias dockps = "docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}""

The syntax for creating an alias is: alias $COMMAND = "docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}""

However, since there are quote marks, I assume they neet to be escaped with \. But in the case above, I’m getting the errors in fish and bash.

Fish error: `$ alias dockps = “docker ps --format "table {{.ID}} {{.Names}} {{.Status}} {{.Ports}}"”

alias: expected <= 2 arguments; got 3`

Bash error: $ alias dockps = "docker ps --format \"table {{.ID}} {{.Names}} {{.Status}} {{.Ports}}\"" bash: alias: dockps: not found bash: alias: =: not found bash: alias: docker ps --format "table {{.ID}} {{.Names}} {{.Status}} {{.Ports}}": not found

What am I doing wrong?

Thanks in advance!

  • humanplayer2@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    10 months ago

    I think you have to alternate the quotations you use between doubles and singles, pairwise. Else the first pair is closed after --format.

    So you have to use a pattern like “command level 1 ‘level 2 “level 3” more level 2’ more level 1”

    Does that make sense?

  • calm.like.a.bomb@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    10 months ago

    As the others have said, your first issue is using blank spaces before and after =

    Then, when you need to use double quotes in a command, the alias should be defined with single quotes, like this:

    \$ alias dockps='docker ps --format "table {{.ID}}  {{.Names}}  {{.Status}}  {{.Ports}}"'
    
    • krash@lemmy.mlOP
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      10 months ago

      Thank you (and all others who replied), this worked flawlessly :-)