flyhawk
flyhawk

Reputation: 19

mac zsh cannot find any folder

I typed "export $GOPATH=/Users/myusername/Desktop/test" into my mac terminal. Then I got an error "zsh: /Users/myusername/Desktop/test not found". I had a folder named test in the Desktop. I tried rebooting my mac but still got the same error.

This is the result of "echo $PATH": /Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

Anyone what's happening?

Upvotes: 0

Views: 802

Answers (1)

user1934428
user1934428

Reputation: 22225

Anyone what's happening?

Since the variable GOPATH was not defined and therefore empty, the command

export $GOPATH=/Users/myusername/Desktop/test

expanded to

export =/Users/myusername/Desktop/test

In zsh =SOMETHING expands to the absolute path of the executable SOMETHING (you can try it with echo =ls), and if the SOMETHING part is already a path, zsh only checks that the executable exists. In your case, /Users/myusername/Desktop/test is not an executable file, and this resulted in the error message.

Of course all the mess was started by the typo in your export statement. This kind of errors can be caught if you put into your ~/.zshrc the command

set -u

This causes an error message whenever you try to expand an uninitialized variable. With this setting, you would get at least a helpful error message (in your case, the message would have been zsh: GOLANG: parameter not set), and you would see the reason for the error.

Upvotes: 1

Related Questions