When I run
export $PATH in bash, I get the error
not a valid identifier. Why?
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 (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
You should use it this way:
just remove the
$ sign from the left hand side.
You probably had a need to append a $PATH to your existing PATH variable ?