0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abdul_Kuddus
  • 23
  • 1
  • 7
  • 1
    Place tall-pointy hat on head and turn and face the corner for 10 minutes....There is no ***space*** allowed surrounding the `=` sign in shell scripting `:)` – David C. Rankin Aug 15 '20 at 03:52
  • @BenjaminW.- much better dupe. Wonder why that didn't come up in my search? Probably the same reason our "Related" pages are silent.... Good job. – David C. Rankin Aug 15 '20 at 04:18

1 Answers1

3

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 =.

vonbrand
  • 11,412
  • 8
  • 32
  • 52