Command not found error in Bash variable assignment?

Assigning a value in Bash

In Bash, if you try to assign a value to a variable using the following syntax:


and you receive a "Command not found" error, it means Bash is interpreting VARNAME=value as a command and not a variable assignment.

The most common reason for this error is when there is a space before or after the equal sign.

For example, if you write:

VARNAME = value

Bash will try to execute the command "VARNAME" with argument "=". Since there is no command named "VARNAME", it will give you a "Command not found" error.

To fix this error, make sure there is no space before or after the equal sign:


or use the export keyword to set the variable and export the value to the environment:

export VARNAME=value

This will ensure that Bash interprets the statement as a variable assignment and not as a command.

  1. Dynamic variable names in Bash
  2. How to parse command line arguments in Bash?
  3. Bash and shell script variable capitalization?
  4. How to get the directory where a Bash script is located from within the script itself?
  5. Parsing JSON with Unix tools
  6. How to set a variable to the output of a command in Bash?
  7. How to run Bash commands in Python?
  8. Extract filename and extension in Bash?
  9. Looping through the content of a file in Bash