if else if


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if else if
# 1  
Old 07-21-2010
Question if else if

hi,

i am trying to get the output of this but not getting.. please help me

I/p

Code:
ENV="ipo5"
if [ [${ENV} == "ip05" ]]; then
echo $ENVNAME="PROD"
elif [ [${ENV} == "ip04" ]]; then
echo $ENVNAME="PREPROD"
elif [ [${ENV} == "ip03" ]]; then
echo $ENVNAME="QA"
fi


Last edited by Scott; 07-21-2010 at 09:32 AM.. Reason: Code tags, please...
# 2  
Old 07-21-2010
Try replacing the curly brackets with normal ones
# 3  
Old 07-21-2010
  • The value of 'ipo5' is not tested. Maybe an 'o' instead of '0'
  • A space is misplaced in the tests, must be after [ and not between [[
  • Variable ENVNAME is not set, or the $ must be removed in the echo statement
Code:
ENV="ip05"
if [[ ${ENV} == "ip05" ]]; then
echo $ENVNAME="PROD"
elif [[ ${ENV} == "ip04" ]]; then
echo $ENVNAME="PREPROD"
elif [[ ${ENV} == "ip03" ]]; then
echo $ENVNAME="QA"
fi

Another way:
Code:
ENV="ip05"
case "${ENV}" in
  ip05)  echo ENVNAME=PROD    ;;
  ip04)  echo ENVNAME=PREPROD ;;
  ip03)  echo ENVNAME=QA      ;;
     *)  echo ENVNAME=Unknown ;;
esac

Jean-Pierre.
# 4  
Old 07-22-2010
Thanks it working Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question