0

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
bluethundr
  • 383
  • 14
  • 49
  • 115
  • 1
    You can't have a space after `aws_account` and after the `=` sign. – Benjamin W. May 09 '18 at 20:51
  • That's it. Thanks! I had to take out the space before and after the = sign. – bluethundr May 09 '18 at 20:55
  • 2
    [ShellCheck](https://shellcheck.net) automatically points out this and other common problems – that other guy May 09 '18 at 20:55
  • BTW, doesn't matter for the immediate case, but it should be `for i in "${arr[@]}"; do` and `if [ "$i" -eq ... ]`; to correctly handle iterating over or testing values with spaces or values that could be empty. Even if you don't expect such values, using the robust syntax means you'll get more useful messages from `[` in the presence of bad data/user error/etc. – Charles Duffy May 09 '18 at 20:59
  • Ok thanks for the tip! I appreciate that! – bluethundr May 09 '18 at 21:04

1 Answers1

0

You can't have a space after aws_account and after the = sign.

bluethundr
  • 383
  • 14
  • 49
  • 115