When I type HELLO="hello", I would expect to create an environment variable called HELLO. Instead, I get the error HELLO=hello: Command not found. What could be going wrong here?

I am on Debian GNU/Linux 9.12, on a shared server where I am not root.

  • Why do you expect it to create an environment variable? It should create a shell variable, you have to use export to copy it into the environment. Do you know the difference?
    – Barmar
    Mar 12 at 15:09
  • I meant to create a shell variable. Now I know the difference.
    – Liam Bohl
    Mar 12 at 17:39
  • 1
    Anyone else with a similar problem, make sure not to include a $ dollar sign at the start. Do NOT type $HELLO="hello", this is where I went wrong. Aug 26 at 9:40

That's the right command to set a shell variable. Or would be, in a POSIX shell. It doesn't actually export the variable to the environment of commands you run, though. To do that, you'd need export HELLO in addition.

See e.g. Difference between shell variables which are exported and those which are not in bash for the difference.

Anyway, the error message you get appears to match the one tcsh gives:

$ tcsh
~> HELLO="hello"
HELLO=hello: Command not found.

And it has a different language. Either use setenv HELLO "hello" to set a variable exported to commands, or set HELLO = "hello" for one that doesn't get exported. Or try to see if you can change your shell to something else (e.g. Bash or Zsh) if you want a POSIX-like shell instead.

  • 1
    most popular would be bash: try running $ bash (type bash as your normal user) to start a bash shell
    – allanlaal
    Mar 11 at 21:45
  • Since he didn't use export, the actual equivalent would be set HELLO = "hello"
    – Barmar
    Mar 12 at 15:10
  • @Barmar, mm, or since they said they wanted an environment variable, I should have said that HELLO="hello" is fine, except it doesn't actually export it.
    – ilkkachu
    Mar 12 at 15:15
  • 1
    I suspect they just don't know the difference between environment and shell variables, and mistakenly use the first term. I've seen it many times. I've also seen many people use export unnecessarily.
    – Barmar
    Mar 12 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.