I am not extremely familiar with KSH (Actually just started using it) and I am having problems with trying to create a script that will essentially compare two arrays that have been stored and then output the difference.Running AIX 6.1 with KSH Version M-11/16/88fHere is what I have thus far:#!/bin/kshset -A dfArray $(df | awk '{print $7}' | grep -v Mounted)set -A dsmArray $(cat dsm.sys | grep DOMAIN | awk '{ s=; for (i = 2; i <= NF; i++) s = s $i  ; print s }')MAX=$((${#dsmArray[*]}-1))for a in ${dfArray[*]}       do       COUNT=0       set -A UNMATCHED       for b in ${dsmArray[*]}               do               (( $a != $b )) && \               UNMATCHED[$COUNT]=$a && \               let COUNT+=1       done       (( ${#UNMATCHED[*]} != $MAX )) && \       print ${UNMATCHED[0]}       unset UNMATCHEDdoneHere are what the two arrays might look like:dfArray://usr/var/tmp...dsmArray:/home/opt/usr...When I run the current script I get the following error:./checkBackup.sh[22]:  / != /home : syntax errorWhat am I doing wrong? I am sure it's probably something simple.Thanks!
Compare two Arrays in KSH and output the difference
shell script;scripting;awk;ksh;array
You get an error because you're attempting to do arithmetic equality with string values.Here are 2 ways to check whether the elements of dfArray are in dsmArrayset -A dfArray / /usr /var /tmp ...set -A dsmArray /home /opt /usr ...for a in ${dfArray[@]}; do  in=false  for b in ${dsmArray[@]}; do    if [[ $a == $b ]]; then      echo $a is in dsmArray      in=true      break    fi  done  $in || echo $a is not in dsmArraydone/ is not in dsmArray/usr is in dsmArray/var is not in dsmArray/tmp is not in dsmArray... is in dsmArrayOr, flattening the dsmArray and avoiding the inner loop:for a in ${dfArray[@]}; do  # all quotes and spaces required below  if [[  ${dsmArray[*]}  == * $a * ]]; then    echo $a is in dsmArray  else    echo $a is not in dsmArray  fidone/ is not in dsmArray/usr is in dsmArray/var is not in dsmArray/tmp is not in dsmArray... is in dsmArrayThis solution keys on this part: [[  ${dsmArray[*]}  == * $a * ]] ${dsmArray[*]} when quoted, ${ary[*]} results in a single string composed of the individual elements of the array joined on the first character of $IFSthe default of $IFS is 3 characters: space, tab, newlinewith the leading and trailing quotes, we get the string  /home /opt /usr ... * $a *inside double brackets, the == operator is actually a pattern matching operator, not strictly equalityour pattern is: zero or more characters, followed bya space, followed bythe value of $a, followed bya space, followed byzero or more charactersSo, for each value of dfArray, we are checking to see if it appears as a space-separated word within the flattened dsmArray string.This breaks down with the array elements can contain spaces. Then you need to assign a new value to IFS and things get messy(-er).To get an array of common elements, I'd dotypeset -i n=0set -A commonfor a in ${dfArray[@]}; do  if [[  ${dsmArray[*]}  == * $a * ]]; then    let n+=1    common[n]=$a  fidoneecho commonprintf %s\n ${common[@]}echo common with indextypeset -i i=1while (( i <= n )); do echo $i  ${common[i]}; ((i+=1)); donecommon/usr...common with index1  /usr2  ...