I'm trying to pass ip_addr (if env = qa, then pass this ip_addr=x.x.x.47 or else ip_addr=x.x.x.53) using ternary operator and also tried using if condition. When I use ternary operator, I'm getting operand expected (error token is ""qa"? error. And, with if condition, error: url is not calling properly and if condition is failing. Could someone help me to fix this issue ? Also, please suggest any other way to fix this issue. Thanks in Advance !
##2: Using ternary operator
#! /bin/bash
env=qa
username=testuser
pass=password
ip_addr = $(( $env == "qa" ? "x.x.x.47" : "x.x.x.53"))
export id=`curl -u "$username:$pass" \
-H 'Accept: application/vnd.go.cd.v4+json' \
-H 'Content-Type: application/vnd.go.cd.v4+json; charset=utf-8' \
'http://'${ip_addr}':8080/test/api/cases'| grep -i '"id":'`
echo "Expected Id is ${id}"
##2: Using if condition
#! /bin/bash
env=uat
username=testuser
pass=password
if (${env} == "qa"); then
ip_addr = "x.x.x.47"
else
ip_addr = "x.x.x.53"
fi
export id=`curl -u "$username:$pass" \
-H 'Accept: application/vnd.go.cd.v4+json' \
-H 'Content-Type: application/vnd.go.cd.v4+json; charset=utf-8' \
'http://'${ip_addr}':8080/test/api/cases' | grep -i '"id":'`
echo "Expected Id is ${id}"