Reputation: 3115
When I open my ~/.zshrc
file and add alias homestead=“cd ~/Homestead”
, I expect to be able to type homestead
and be taken to the Homestead folder.
Instead I get the following error:
zsh: command not found: “cd
Even when I use single quotes, i.e. alias homestead='cd ~/Homestead'
and run source ~/.zshrc
I get the same error.
UPDATE: Also, when I run which homestead
I get homestead: aliased to "cd
How can I fix this?
Upvotes: 1
Views: 4244
Reputation: 1106
Just saying that for me what fixed it was an error in the first alias in my list that had a question mark in it.
Just switched to Mac OS Catalina and ~/.bashrc
to ~/.zshrc
and I guess zsh doesn't support question marks.
Maybe it'll help someone coming here from Google search like I did.
Upvotes: 0
Reputation: 1551
Maybe your locale settings is auto correcting a double quote " into a localized double quote “ as you posted. Since this is not recognized as a valid quote in shell, a simple white-space would break the string. So the actual alias is “cd
.
As to why alias homestead='cd ~/Homestead'
does not work, it seems you changed the alias in ~/.zshrc
. From the which homestead
result, it can be seen that alias homestead='cd ~/Homestead'
does not really work. Maybe there is another line of alias homestead=“cd ~/Homestead”
hidden in .zshrc
after it.
Upvotes: 0
Reputation: 3115
The answer was to open ~/.zshrc
in Sublime Text as opposed to TextEdit and to check that the "
were coming up as 042
in an octal dump.
Upvotes: 2
Reputation: 532333
You don't need to define this alias at all in zsh
. Add the following to your .zshrc
:
setopt autocd
cdpath+=(~)
The first allows you to treat a directory name as a command, which implicitly sets the working directory of the current shell to the named directory. The second specifies that if the current directory doesn't have a directory whose name is used with cd
(or by itself with autocd
set), then try to find it in a directory named in the cdpath
parameter.
With these two, simply typing Homestead
will first try to run a command named Homestead
; failing that, it tries to cd
to ./Homestead
, and failing that, will finally succeed in cd
ing to ~/Homestead
.
Upvotes: 1
Reputation: 72756
The double quotes must be ASCII, not Unicode outside the ASCII range. Load the file in your editor, disable any automatic mangling of single quotes and double quotes. Then replace the funny quotes with ASCII quotes "
(code decimal 34, hex 22, octal 042). Or type the command at a prompt, then cut & paste it in your editor. If all else fails, add the alias at the end of your .zshrc
with
printf 'alias homestead="cd ~/homestead"' >> ~/.zshrc
Verify the result with octal dump,
od -bc .zshrc
The number above the quotes should appear as 042
.
Upvotes: 0