'How to fix command not found in Linux shell scripting [duplicate]

I have a Linux shell script with the below code

#! /bin/bash
echo $BASH
name = Mark
echo $name

When I run the script, I'm getting an error:

./my_script.sh: line 3: =: command not found

What am I doing wrong?

Note: I'm using Kali Linux.



Solution 1:[1]

In shell, you need to write:

echo $BASH
name=Mark
echo $name

Note there are no spaces around = when setting a variable. The shell usually interprets name = Mark as calling the command name with arguments =and Mark, hardly what you intend. It also seems that name somehow expands to nothing (an alias?), thus the confusing message about command =.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vonbrand