When I run export $PATH in bash, I get the error not a valid identifier. Why?


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".

  • Basically I have created some variables, JAVA_HOME, MAVEN_HOME and want to make sure that bash has properly set them, so I export $PATH to see if the path variables have been properly set to the PATH variable – ThaSaleni Jun 17 '13 at 10:04
  • 1
    This is shell dependent, not OS dependent. I would be surprised if export ever worked like that in Bash. – l0b0 Jun 17 '13 at 10:04
  • Additionally, the PATH variable is already exported and does not need to be exported again. – Kusalananda Apr 14 '18 at 9:57

The following command export $PATH=somePath will return not a valid identifier and that is because of the $ before the PATH variable.


export PATH=somePath


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.


You probably had a need to append a $PATH to your existing PATH variable ?

export PATH=$PATH:/something/bin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.