#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_array_fields_differ.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 # @(#)18 1.4 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_array_fields_differ.sh, hacmp, 61haes_r714 11/28/11 15:19:22 # #=head1 NAME # # KLIB_UTIL_LIST_array_fields_differ - Return a list of fields that are different # #=head1 SYNOPSIS # # typeset -A array_1 # typeset -A array_2 # typeset differences # array_1( \ # [test]="foo" # [abc]="def" # ) # # array_2( \ # [test]="123" # [abc]="def" # ) # # KLIB_UTIL_LIST_array_field_differ array_1 array_2 differences # for $key in ${differences[*]}; do # echo "field: $key is different" # done # #=head1 DESCRIPTION # # Determines the differences between two KSH93 hash arrays # and places those differences into a third hash array # #=head1 ARGUMENTS # # 1: [by ref] first hash array to use in comparison # 2: [by ref] second hash array to use in comparison # 3: [by ref] resultant diff, this list will contain those field elements # that are different between the first and second arrays # #=head1 RETURN # # None - see 3rd array as output # #=head1 COPYRIGHT # #(C) COPYRIGHT International Business Machines Corp. 2005 #All Rights Reserved # #=cut # # Name: KLIB_UTIL_LIST_array_fields_differ # # Description: Make a list of fields that differ # # Arguments: First array variable # # Second array variable # # String variable to return list in # # Returns: True if there are array fields that differ # # Results: String list of differing fields # # Global Refs: None # # Usage: KLIB_UTIL_LIST_array_fields_differ array1 array2 string_var # Return: list of fields that differ function KLIB_UTIL_LIST_array_fields_differ { . /usr/es/lib/ksh93/func_include typeset -n arr1=$1 typeset -n arr2=$2 typeset -n errlist=$3 errlist= typeset keylist KLIB_UTIL_LIST_unique_key_list keylist ${!arr1[*]} ${!arr2[*]} typeset key for key in $keylist; do [[ "${arr1[$key]}" != "${arr2[$key]}" ]] && errlist="${errlist:+$errlist }$key" # clean append idiom done [[ -n "$errlist" ]] }