this post was submitted on 20 Jan 2024
18 points (100.0% liked)

Linux

1259 readers
87 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] clmbmb@lemmy.dbzer0.com 16 points 10 months ago (1 children)

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:

\$&nbsp;alias&nbsp;dockps='docker&nbsp;ps&nbsp;--format&nbsp;"table&nbsp;{{.ID}}&nbsp;&nbsp;{{.Names}}&nbsp;&nbsp;{{.Status}}&nbsp;&nbsp;{{.Ports}}"'
[–] krash@lemmy.ml 5 points 10 months ago* (last edited 10 months ago)

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