Define an alias and use it in the same breath – and zsh does not know it. The reason is timing: zsh expands aliases while reading the whole line, when the alias did not exist yet.
Symptom
alias gl2='git log --oneline -3'; gl2 zsh: command not found: gl2
Split over two lines, the same alias works.
Diagnosis
Use alias and type to see what a name is.
alias gl1 type gl1 unalias gl1 gl2 type gl1 gl1='git log --oneline -3' gl1 is an alias for git log --oneline -3 gl1 not found
Causes
gl2Alias unknown while reading
zsh reads the whole line, expands aliases and only then runs it. While reading, gl2 did not exist yet. The same applies in files: an alias takes effect from the next line on.
Fix
alias gl1='git log --oneline -3' gl1 2e4e6aa (HEAD -> main) chore: Config, Manifeste, Report a57983c feat: Warenkorb und HTTP-Server 1dc0abc init: Projektgerüst
Don't: Build eval tricks for this. If a shortcut is needed on the same line, a function is the better choice.
The Mac terminal hands-on, Day 5: aliases and functions in zsh.
Go to day 5 →
FAQ
How do I make an alias permanent?
Ad-hoc aliases vanish with the shell. It only becomes permanent in a file zsh reads at startup.
How do I bypass an alias once?
With \ls or command ls – the backslash or command uses the original.