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


4 Answers 4


Running export $PATH will try to export a variable with a name equal to the value of $PATH (after word splitting and filename generation). 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 when not called within a function) in Bash maps the shell variable to an environment variable, so it is passed to commands executed from now one (in child processes or otherwise).

To print the value of a variable safely and readably, use printf '%q\n' "$PATH" or typeset -p PATH to print its definition.

  • 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, 2013 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, 2013 at 10:04
  • Additionally, the PATH variable is already exported and does not need to be exported again.
    – Kusalananda
    Apr 14, 2018 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .