1

Im trying to make work the next bash code, but seems that Im doing things wrong:

hostname=`hostname -s`
qaiservers={'v-qai01' 'v-qai02'}


for i in ${qaiservers[@]}
do
        if [[ $i = ${hostname} ]]; then
                echo 1
        else
                echo 0
        fi
done

The current hostname is v-qai01 which is supposed to match with the verification, but it doesnt:

./run.sh: line 14: v-qai02}: command not found
./run.sh: line 15: }: command not found

Thank you

FIXED:

Made it work with:

hostname=`hostname -s`

qaiservers=("v-qai01" "v-qai02")
#portales={'t1wsyellar01' }

for i in "${qaiservers[@]}"
do
    if [ "$i" == "${hostname}" ] ; then
        echo "Found"
    fi
done

Made it work thanks to this link

1
  • Only use the == operator within [[ double brackets ]] Commented May 10, 2011 at 21:15

1 Answer 1

2
qaiservers=('v-qai01' 'v-qai02')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.