On Wed, 3 Aug 2005, Dave Anderson wrote:

> Something's screwy here, using the 'set -A' command in /bin/sh on
> 3.7-release.  AFAICT the complicated file-match expression should (in
> this case) produce the same results as the simple one, but it doesn't
> seem to match at all when used in this script -- but does produce the
> expected result when cut-and-pasted to a command line.
> 
> Any constructive comments would be greatly appreciated.


I do not understand this yet, but the desired behaviour is achieved if
you force the file name matching to be done in the call:

#!/bin/sh
function DoIt {
  set -A files $*
  echo "match = '$1'"
  typeset -i idx
  idx=0
  while [ idx -lt ${#files[*]} ] ; do
    echo "files[$idx] = '${files[$idx]}'"
    idx=idx+1
  done
  return 0
}
DoIt /tmp/tst/*
echo ""
DoIt 
/tmp/tst/+([a-zA-Z])+([0-9]).@(in|out).@(block|pass).@(destIP|destPort|srcIP)

$ sh x
match = '/tmp/tst/ne3.in.block.destIP'
files[0] = '/tmp/tst/ne3.in.block.destIP'
files[1] = '/tmp/tst/ne3.in.block.destPort'
files[2] = '/tmp/tst/ne3.in.block.srcIP'

match = '/tmp/tst/ne3.in.block.destIP'
files[0] = '/tmp/tst/ne3.in.block.destIP'
files[1] = '/tmp/tst/ne3.in.block.destPort'
files[2] = '/tmp/tst/ne3.in.block.srcIP'

Alternatively, adding an 'eval' before the 'set' command also fixes
the problem:

#!/bin/sh
function DoIt {
  eval set -A files $1
  echo "match = '$1'"
  typeset -i idx
  idx=0
  while [ idx -lt ${#files[*]} ] ; do
    echo "files[$idx] = '${files[$idx]}'"
    idx=idx+1
  done
  return 0
}
DoIt "/tmp/tst/*"
echo ""
DoIt 
"/tmp/tst/+([a-zA-Z])+([0-9]).@(in|out).@(block|pass).@(destIP|destPort|srcIP)"


        -Otto

Reply via email to