The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to assign a variable value to array? balamv Shell Programming and Scripting 2 06-06-2008 03:33 AM
creating array variable scriptingmani Shell Programming and Scripting 2 06-28-2007 10:25 AM
Check whether the pattern is present or not? skyineyes Shell Programming and Scripting 8 06-27-2007 09:42 AM
AWK program with array variable whatisthis Shell Programming and Scripting 4 05-18-2005 11:07 AM
how to check if path is present? svennie UNIX for Dummies Questions & Answers 3 11-02-2004 06:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-04-2009
padhu.47 padhu.47 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
Question How to check the variable is present in array or not ?

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.


###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 ####
echo " Its a valid ORG ID "

else

echo " Its INVALID ORG ID - $1 "

echo " Please specify a valid ORG ID "

exit 1

fi
  #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,313
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0