I'm trying to write a bash script that asks a user to enter an account number, and then performs an action on that account. Right now, I'm just using a print statement until I can get this to work.
I'm getting an error when I try to add a variable inside the if statement.
This is my script (so far):
#!/bin/bash
echo "What AWS Account: "
read accountnumber
echo "You entered $accountnumber"
declare -a arr=("1234556789" "1234567810")
for i in ${arr[@]}
do
if [ $i -eq 1234556789 ]; then
aws_account = "lab"
echo "You are currently in account: $aws_account"
break
elif [ $i -eq 1234567810 ]; then
aws_account = "bill"
echo "You are currently in account: $aws_account"
break
else
echo "Unkown account"
fi
done
But I'm getting this error when I try and run the script. It looks like I'm unable to assign the variable:
./delete_snapshots.sh
What AWS Account:
1234556789
You entered 1234556789
./delete_snapshots.sh: line 12: aws_account: command not found
You are currently in account:
Why does this bash script think that aws_account is a command, and not a variable that I'm trying to assign? How can I assign this variable based on the user's input?
Also how can I get the user to input the text on the same line as the question?
Instead of:
What AWS Account:
1234556789
How do I get:
What AWS Account: 1234556789