[SLUG] Re: quoting

From: Eben King (eben01@verizon.net)
Date: Fri Jun 02 2006 - 00:56:17 EDT


On Thu, 1 Jun 2006, Eben King wrote:

>
> What I've got is a shell script, written in ksh (think of it as a dialect of
> bash):
>
> ...
> 40 function choose_a_background
...
> So, I need to add "-name tall\*" or "! -name tall\*" to find's options. I've
> tried between 1 and 6 backslashes in line 47, single quotes around tall_\\*
> with varying numbers of backslashes, reducing "$BACKGROUNDDIR $PATTERNDIR" to
> "/export", reducing tall_\\* to \\*, and what I've found out is that:
...
> So, can anyone see where I've screwed up?

I finally settled on "just make it work, forget about making it pretty":

40 function choose_a_background
41 {
42 [[ -z $BACKGROUNDDIR ]] && BACKGROUNDDIR=/export/media/backgrounds
43 [[ -z $PATTERNDIR ]] && PATTERNDIR=/export/media/patterns
44
45 case $1 in
46 tall)
47 bang="" ;;
48 wide)
49 bang="!"
50 esac
51
52 # Initialize PRNG in ksh
53 [[ -c /dev/random ]] \
54 && RANDOM=$( dd if=/dev/random bs=4 count=1 2>/dev/null \
55 | sum - \
56 | cut -f 1 -d " " )
57
58 numfiles=$(find $BACKGROUNDDIR $PATTERNDIR -type f $bang -name tall_\* ! -name random\* | wc -l)
59 print -u2 found $numfiles files

Probably the solution relies on the deft use of "eval". I had hoped that I
could save all the images' names into an array and thereby count them, so
I'd only have to do one "find". But it seems arrays are limited to (2^10)-1
(aka 1023) entries, so that won't happen that way.

-- 
"The Web brings people together because no matter what kind of a twisted
  sexual mutant you happen to be, you've got millions of pals out there.
  Type in 'Find people that have sex with goats that are on fire' and the
  computer will say, 'Specify type of goat.'" -- Rich Jeni
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:00:07 EDT