Shell – fish: whitespace in alias

aliasfishshell

I am trying to alias an executable in a directory with a space in it. For example:

alias myfile="/home/ben/test case/myfile"

Now, this is not expanded the way I want (it thinks /home/ben/test is the executable). In bash you can add extra quotes:

alias myfile="'/home/ben/test case/myfile'"

Sadly, in fish this does not work. What should I do instead?

Best Answer

alias in fish is just a wrapper for function builtin, it existed for backward compatible with POSIX shell. alias in fish didn't work as POSIX alias.

If you want the equivalent of POSIX alias, you must use abbr, which was added in fish 2.2.0:

abbr -a myfile "'/home/ben/test case/myfile'"

or:

abbr -a myfile "/home/ben/test\ case/myfile"
Related Question