Ubuntu – Can’t set alias in zsh — command not found

command linezsh

I'm trying to set alias conky-lua ="conky -c ./.conky/conkyrc &" so to start conky-lua. but when I source .zshrc it says command not found.

A possible solution that I found on Stackoverflow is to set alias ls='ls -GpF'didn't solve the problem

Best Answer

The problem is the space around the = in the command. Look:

[:~] % alias a=ls 

this works as expected

[:~] % type a
a is an alias for ls

But

[:~] % alias b =ls    
[:~] 1 % 

This does not work. zsh see two words, b and =ls; it uses the pathname expansion on the second one, and execute alias b /bin/ls --- it exits silently with error code 1 because neither b or /bin/ls are alias (alias without = checks if a name is an alias).

[:~] 1 % alias c ="ls -l"
zsh: ls -l not found
[:~] 1 % 

This fails in a more strange way; the shell is trying to expand the full path of the command "ls -l" (with the embedded space in the command name) and so it is failing in looking for it.

Related Question