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!

Edit: For fish shell users out there, this can be accomplished by using func: $ function dockerps docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}" end $ funcsave dockerps

I’m leaving the question up as the question with escape characters is still relevant and can be a learning resouce.

  • JDubbleu@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    9 months ago

    Not at my computer so I can’t double check, but I believe you can replace the outer double quotes with single quotes. I’d also remove the spaces before and after the equal sign for the alias. I don’t know about fish but I know bash doesn’t like when you add spaces there.