Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does zsh alias not evaluate properly the nested command?

Tags:

docker

zsh

In my ~/.zshrc i set up an alias

alias dkill="docker kill $(docker ps -q)"

but it does not actually run like the command itself does.

For some reason it tries to execute container names as commands instead of passing them to the docker kill command.

Error response from daemon: Cannot kill container: 3f1xxxxx0c4: No such container: 3f1xxxxx0c4
zsh: command not found: 0aexxxxxx913
zsh: command not found: 46acxxxx75cd
zsh: command not found: 20f9xxxxx9c1
zsh: command not found: 63edxxxxc085
zsh: command not found: 6328xxxxfe4d

How should i redefine the alias to kill containers properly

like image 633
Repastificationer Avatar asked Oct 29 '25 11:10

Repastificationer


1 Answers

As @triplee says, the command is evaluated as soon as you define the alias (when you open you zsh session, container might not exist).

In your .zshrc use a function instead:

function dkill { docker kill $(docker ps -q) }

Or use single quotes:

alias dkill='docker kill $(docker ps -q)'
like image 87
Robert Avatar answered Nov 01 '25 10:11

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!