zsh error: export:54: not valid in this context:
Asked Answered
D

4

18

While messing around with zsh today and getting something configured properly for ruby, I got the following error.

/Users/secallahan/.zshrc:export:54: not valid in this context: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin

Here is my .zshrc (around line 54, where the error occurs) file that I edited.

# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh

....
....

# User configuration

export $PATH=/Users/secallahan/.rvm/gems/ruby-2.1.1/bin:/Users/secallahan/.rvm/gems/ruby-2.1.1@global/bin:/Users/secallahan/.rvm/rubies/ruby-2.1.1/bin:/Users/secallahan/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin
# export MANPATH="/usr/local/man:$MANPATH"

This was the only way I was able to make it. So then I opened a new shell and did ruby -v and got ruby2.1.1 as the current version.

Any help would be very much appreciated.

Deplane answered 14/3, 2014 at 1:21 Comment(1)
FYI, you don't need to use export when updating PATH, since PATH will universally have the export flag set already. export is only needed when marking a variable for export which didn't have the flag previously set.Kiowa
W
22

When defining or exporting a variable, you should not use $:

export PATH=/Users...

Otherwise, the current value of PATH will be substituted into the export statement.

Whalebone answered 14/3, 2014 at 1:46 Comment(2)
Ahh that makes sense. That worked perfectly, thanks! Just to spin off another question form that, what exactly does the $ do?Deplane
it means "use the variable's value"... e.g. echo PATH outputs the word "PATH", echo $PATH outputs the value of the PATH variable.Whalebone
S
3

This can also be caused by using pasted incorrect double quotes for your value To fix it delete your double quotes and type them in terminal

For example:

export CPPFLAGS=“-I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/zlib/include”

is wrong and needs to be:

export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/zlib/include"
Stationer answered 17/6, 2022 at 18:41 Comment(0)
D
1

You left out the double quotes too. This was my case, I had to change the syntax from

export PATH=/usr/local/opt/node@12/bin/  to

export PATH="/usr/local/opt/node@12/bin:$PATH"
Disaccord answered 5/5, 2022 at 10:54 Comment(0)
I
0

This happened to me when I ran source .env command. The reason was space between double quotes and equals to.

export API_KEY= "#####"

Fixed it by removing space.

export API_KEY="#####"

Isocline answered 30/8, 2023 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.