Variables in Bash ": command not found"

Read {count} times since 2020

Bash is like the very complicated language, even a space can make a syntax error. But, when you get into it often, you will get a hang of it and it will be easy.

This post is a solution to one of the most common problems that happen to a newbie in Bash and it’s about a single whitespace.

Here is a sample Bash file :

a = 50
echo $a

and when you execute it, the error will be as follows : line 1: a: command not found

This error is produced by the error in defining the variable “a”. There should be no space before or after the “=”. If you remove it, then the script will run successfully.

When there is a space after “a”, Bash thinks that “a” is a command followed by it’s attributes. Since there is no command named “a”, it will produce a “command not found” error.

Show Comments