When I run export $PATH in bash, I get the error not a valid identifier. Why?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Running export $PATH will try to export a variable with a name equal to the value of $PATH (after word splitting). That is, it’s equivalent to writing something like export /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. And since /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin is not a valid variable name, it fails. What you want to do is export PATH.
export (equivalent to declare -x) in Bash simply makes the variable available to subshells.
To print the value of a variable safely and readably, use printf %q "$PATH".
Method 2
The following command export $PATH=somePath will return not a valid identifier and that is because of the $ before the PATH variable.
solution:
export PATH=somePath
Method 3
You should use it this way:
export PATH=$PATH:/something/bin
Instead of:
export $PATH=$PATH:/something/bin
just remove the $ sign from the left hand side.
Method 4
You probably had a need to append a $PATH to your existing PATH variable ?
export PATH=$PATH:/something/bin
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0