-3

I write the bash script with the case, and when I run it as follow ./myscript.sh us-west-1d It causes the error

./myscript.sh: line 26:  : command not found
./myscript.sh: line 27:  : command not found
./myscript.sh: line 28:  : command not found
ami-fce3c696 us-east-1

But, when I run ./myscript.sh us-west-1b, it runs normally

Can anyone please show me how to fix this problem?

#! /bin/bash
AZ=$1
case $AZ in
      us-east-1b)
              SUBNET="subnet-2a3b5d47"
              SECURITY_GROUP=sg-f7d52998
              INVENTORY_GROUP=collector-use1
              WEIGHT=100
              AMI=ami-fce3c696
              REGION=us-east-1
              ;;
      us-east-1d)
              SUBNET="subnet-e6385e8b"
              SECURITY_GROUP=sg-f7d52998
              INVENTORY_GROUP=collector-use1
              WEIGHT=100
              AMI=ami-fce3c696
              REGION=us-east-1
              ;;
      us-east-1e)
              SUBNET="subnet-07395f6a"
              SECURITY_GROUP=sg-f7d52998
              INVENTORY_GROUP=collector-use1
              WEIGHT=100
              AMI=ami-fce3c696
              REGION=us-east-1
              ;;
esac
echo $SUBNET $SECURITY_GROUP $INVENTORY_GROUP $AMI $REGION
Alexander
  • 282
  • 1
  • 4
  • 13

1 Answers1

0

I replaced the space with tab for all the line in my case, and it turned out working perfectly fine. Thank you everyone for your help

Alexander
  • 282
  • 1
  • 4
  • 13
  • 2
    Tabs are equivalent to spaces in every shell I am familiar with. The problem must have been somewhere else. – tripleee Mar 16 '16 at 19:33
  • 1
    Maybe they were non-breaking spaces or some other unicode whitespace. @Alexander, what editor do you use? – glenn jackman Mar 16 '16 at 19:34
  • @glennjackman you are right. Some other codes with the whitespace, and a few with `tab`. So, I replaced everything with `tab` and it turned out working fine for me – Alexander Mar 16 '16 at 19:42
  • @glennjackman, I used vim editor, which is already available on MAC – Alexander Mar 17 '16 at 06:07
  • If you still have the original script (with the error), or can recreate it, have a look at it with `od -cx` or a hex editor to see whether it contains some odd characters. BTW, when you are posting this type of question, where a line number is mentioned, you should also indicate, where line 26 etc. are in your script. – user1934428 Mar 17 '16 at 08:02
  • @user1934428 it is in the case 1d, I am pretty much sure about it. Moreover, it is a piece of code that I wrote, so that's why it appear as line 26. – Alexander Mar 19 '16 at 07:36
  • I had the same problem where my script was ending with `unknown command: sac` (which was `esac` but it kept eating the first character), and replacing each 4-spaces group with a `\t` fixed the error. No other changes were done to fix it, so looks like mixing whitespaces and tabs actually **is** the cause of the error. – sox supports the mods May 19 '21 at 14:35