0

I'm newer on bash scripting ,I have a global variable that I want to change his value insead a loop in my script but still get an error that commande not found

this my script :

SCRIPT_BASE = "/home/scripts/test-Scripts"
CURRENT_SCRIPT_PATH = ""


declare -a arr=("A" "B"  "C" "D")

for i in "${arr[@]}"
do
   if [ $i == "A" ]; then
       CURRENT_SCRIPT_PATH = $SCRIPT_BASE 
       echo -e "Current Path  :  $CURRENT_SCRIPT_PATH"
   fi
done

when I run this script I get that CURRENT_SCRIPT_PATH commande not found Thanks in advance for any help

e2rabi
  • 4,728
  • 9
  • 42
  • 69

1 Answers1

1

In bash you should be really cautious about spaces in if conditions but also when you assign a value to a variable.

Replace in your code the following tree lines:

SCRIPT_BASE="/home/scripts/test-Scripts"
CURRENT_SCRIPT_PATH=""
CURRENT_SCRIPT_PATH=$SCRIPT_BASE

If you keep a space after the variable name bash will interpret it as a command and as you do not have commands SCRIPT_BASE, CURRENT_SCRIPT_PATH, CURRENT_SCRIPT_PATH in your current $PATH you have the error command not found that is produced.

e2rabi
  • 4,728
  • 9
  • 42
  • 69
Allan
  • 12,117
  • 3
  • 27
  • 51