"not a valid identifier" when I do "export $PATH"

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


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


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.