#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_is_in_list.sh 1.4 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2005,2011 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)14 1.4 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_is_in_list.sh, hacmp, 61haes_r714 11/28/11 15:14:50 # #=head1 NAME # # KLIB_UTIL_LIST_is_in_list - Informs caller if a value is in the list # #=head1 SYNOPSIS # # typeset list="a b c d e f g" # KLIB_UTIL_LIST_is_in_list list "c" && { # echo "Element c is in the list" # } # #=head1 DESCRIPTION # # Informs caller if a value is in the list # #=head1 ARGUMENTS # # 1: [by ref] array to search (haystack) # 2: [scalar] value to search for (needle) # #=head1 RETURN # # 0: value is in the list # 1: value is not in the list # #=head1 COPYRIGHT # #(C) COPYRIGHT International Business Machines Corp. 2005 #All Rights Reserved # #=cut # function KLIB_UTIL_LIST_is_in_list { . /usr/es/lib/ksh93/func_include typeset -n array=$1 value=$2 for element in $array; do [[ "$element" == "$value" ]] && return 0 done return 1 }