Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing exceptions 2

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
I have a script which looks something like
Code:
#!/bin/ksh
for file in *
do
  # Skip known exceptions
  [[ $file = this ]] && continue
  [[ $file = that ]] && continue
  [[ $file = other ]] && continue
  process_file $file
done
Now I want to pass the exceptions as parameters. The best I can think of is
Code:
#!/bin/ksh
for file in *
do
  doit=TRUE
  for exception in $@
  do
    [[ $file = $exception ]] && doit=FALSE
  done
  [[ $doit = TRUE ]] && process_file $file
done
I hate using temporary variables (doit) and there must be a better way. Any suggestions?

Thanks

On the internet no one knows you're a dog

Columb Healy
 

Try this:
Code:
#!/bin/ksh
for file in *
do
  doit=`echo "$@"|grep -w $file"`
  [[ -z $doit ]] && process_file $file
done
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
That's great - I've amended it to
Code:
#!/bin/ksh
for file in *
do
  echo $@|grep -wq $file || process_file $file
done

On the internet no one knows you're a dog

Columb Healy
 
Another way:
Code:
#!/bin/ksh
for file in *
do
  for exception in $@
  do
    [[ $file = $exception ]] && continue 2
  done
  process_file $file
done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ah, so continue can take a parameter - nice one PH!

On the internet no one knows you're a dog

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top