I have the following /etc/environment:
export PATH=$PATH
Whenever I log in I get the following errors:
-bash: id: command not found
-bash: tty: command not found
What am I doing wrong?
(my actual /etc/enviroment is more complicated and sets up java onto the path but for simplicity I cant even get the above to work)
I'm using Centos6
You've misunderstood the
/etc/environment
syntax. It's not interpreted as a series of shell commands, so it isn't a.sh
file at all. The/etc/environment
is loaded when the shell doesn't exist yet, and when it's still not decided whether there would bebash
orcsh
or other. There might even be a customization to run some specific program instead of a shell. Hence/etc/environment
has a really basic syntax.As seen on this Unix/Linux StackExchange answer:
In your case, you shouldn't have used
export
shell command.I think the cleaner approach is to use an entry in
/etc/profile.d
over/etc/environment
, but can you echo the output of $PATH? That may be the real issue. Or at least show the complicated environment file's details.This sounds like a quoting problem (i.e. the current value of
$PATH
contains IFS characters and bash is trying to execute some part of it). Variable values should almost always be quoted, so that line should look like:However, since you're not changing the value of
$PATH
you don't actually need the assignment, and the following is sufficient: