1

In the command line, I appended a directory to my PATH without exporting it:

$ PATH='$PATH:/home/user/anaconda3/bin'

For some reason this has overwritten the PATH environment variable but I'm not sure why this happened. The PATH above is still a colon separated list of directories like it should be so what's the problem? I usually prepend a new directory to my PATH but this time I tested appending it instead which caused unexpected outcomes.

Now any time I try even the simplest commands like ls I get this error (which I expect) followed by a prompt asking me to install the command I typed:

bash: sed: command not found...

Additionally, since I didn't acually export PATH, the subsequent commands are not supposed to inherit the environment of the above PATH variable so what caused it to happen?.

I know I can open a new terminal window to fix it but I'm interested in knowing why this happened?

bit
  • 1,106

1 Answers1

4

Single quotes suppress parameter expansion.

$ foo=42
$ echo '$foo' "$foo"
$foo 42
  • yes, that was it. Does this also apply to environment variables defined in scripts like .profile and .bashrc? – bit Jul 11 '18 at 17:56
  • Also using your example $ echo "$foo" '$foo' '"$foo"' "'$foo'" ouputs 42 $foo "$foo" '42' – bit Jul 11 '18 at 18:03
  • 1
    It applies to all parameter expansion everywhere. – Ignacio Vazquez-Abrams Jul 11 '18 at 18:06
  • then its a good thing I never tried this in .profile or any other environment variable containing files - such a subtle difference yet substantial consequences. – bit Jul 11 '18 at 19:08
  • The choices between those substantially different consequences have to be made so often it's worth offering such convenient, even subtle shorthand for specifying which of the possible outcomes you want this time. – jthill Jul 11 '18 at 20:32