1

I'm trying to write a bash script that imports all users and for each account execute some action.

a="some account"
b="some account" 
#... so on

USERS = #get imported

for ACCOUNT in $USERS; do
        if ["$ACCOUNT" == "$a"] || ["$ACCOUNT" == "$b"] || ["$ACCOUNT" == "$c"] || ["$ACCOUNT" == "$d"]; then
                echo "Skipping $ACCOUNT"
        else
                echo "this"
                echo "this $ACCOUNT"
        fi
done

But there seems to be an issue. For every account, I get following:

[thisis@anaccount: not found

I've tried getting rid of single brackets and place the entire if clause into a double bracket, but that resulted in the same error.

I've also deleted the double quotation marks for each variable calls, but that doesn't seem to be the issue.

Can anybody advise?

viviboox3
  • 309
  • 1
  • 6
  • 20

1 Answers1

2

You are just missing a few spaces ...

#!/bin/bash 
a="ACC_A"
b="ACC_B" 
c="ACC_C"
d="ACC_D"

USERS="ACC_A ACC_B ACC_C ACC_X ACC_Y ACC_Z" 

for ACCOUNT in $USERS; do
        if [ "$ACCOUNT" = "$a" ] || [ "$ACCOUNT" = "$b" ] || [ "$ACCOUNT" = "$c" ] || [ "$ACCOUNT" = "$d" ]; then
              echo "Skipping $ACCOUNT"
    else
              echo "this $ACCOUNT"
    fi
done

and a quick test:

$ bash accounts.sh 
Skipping ACC_A
Skipping ACC_B
Skipping ACC_C
this ACC_X
this ACC_Y
this ACC_Z
chepner
  • 497,756
  • 71
  • 530
  • 681
andipla
  • 363
  • 4
  • 9