I'm trying to translate some useful aliases from zsh to eshell (because ansi-term sucks).

This is one such alias: alias l "ls -lAh $*"

I want this to be able to receive any number of arguments (because ls can handle any number of args) but I still want this to work without arguments.
Now when I type l in eshell the $* expands to null and ls -lAh null is not a valid command.

I could write wrappers for some of my frequently-used shell commands, but isn't there any better way to do this?

Doesn't eshell have a mechanic for simple substitution instead of aliases behaving like lisp functions?

If this is the only way to do things in eshell, Is there any way to make $* expand to whitespace when it's empty or something?

  • I think you just used the wrong sort of quotes: alias l 'ls -lAh $*' behaves correctly with zero or more arguments.
    – Omar
    Commented Mar 30, 2019 at 5:03

1 Answer 1


Well, I found something that helped me.

EmacsWiki says to do this: alias | sed -E "s/^alias ([^=]+)='(.*)'$/alias \1 \2 \$*/g; s/'\\\''/'/g;" >~/.emacs.d/eshell/alias
The above line is for bash (and the location of the alias file is wrong).

For zsh something like this should work:
alias | sed -E "s/^([^=]+)='(.*)'$/alias \1 \2 \$*/g; s/'\\\''/'/g;" >~/.emacs.d/.cache/eshell/alias

And then modify a few aliases by hand to fit eshell's format (this doesn't take care of aliases that don't follow the format <alias>='command' and I lack the regex-fu knowledge to fix it, basically I need to replace the the parts that search for only single-quotes to allow unquoted words too, or you could make sure your aliases are all in the format I described above).

I don't know what I was doing wrong before but this works!

  • I'd like to offer what I think is a simpler sed expression. If I'm reading that correctly it looks like it is simply removing the = sign (for bash, and also prepending the word alias for zsh) ... for bash, the following works for me: alias | sed -e 's/=/ /' >> ~/.emacs.d/eshell/bash_alias for zsh is is only slightly more complex (unless I'm missing something about how zsh may emit oddly formed aliases): alias | sed -r -e 's/^([^=]+)=/alias \1 /' >> ~/.emacs.d/eshell/zsh_alias
    – Mylo Stone
    Commented Mar 25, 2019 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.