The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-04-2009
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378
Quote:
Originally Posted by padhu.47 View Post
Hi ,

I am trying to check wether the variable is present in the array. please see the below code .when ever i do this its taking only the first value of the array . please advise.

When posting code, please put it between [code] tags and post enough to demonstrate your problem, but no more.
Quote:

Code:
###Code Snnipet ###

#!/bin/ksh

set -xv

if [[ -n $1 ]]; then

echo " you have Specified the ORG ID - $1 "

else

echo " Please specify a valid three digit GNS-ORG-ID "

exit 1

fi


ORG=$1


set -A ORGID 211 233 244 300 143 234 222 564 586 810 975



#echo "${#ORGID[*] }"
#echo "${ORGID [2] }"

printf ${ORGID[*]}

if [[ $ORG == ${ORGID[*]} ]]; then    <== Here its checking only with first value of the array ####

case ${ORGID[*]} in
*"$ORG"*) echo valid ;;
*) echo Invalid ;;
esac
Quote:
Code:
echo " Its a valid ORG ID "

else

echo " Its INVALID ORG ID - $1 "

echo " Please specify a valid ORG ID "

exit 1

fi