[SLUG] quoting

From: Eben King (eben01@verizon.net)
Date: Thu Jun 01 2006 - 18:57:58 EDT


OK, I can't figure this out. I'm sure it's logical, but I don't have a
handle on the logic.

What I've got is a shell script, written in ksh (think of it as a dialect of
bash):

...
40 function choose_a_background
41 {
42 [[ -z $BACKGROUNDDIR ]] && BACKGROUNDDIR=/export/media/backgrounds
43 [[ -z $PATTERNDIR ]] && PATTERNDIR=/export/media/patterns
44 FIND_FLAGS="$BACKGROUNDDIR $PATTERNDIR -type f"
45 case $1 in
46 tall)
47 FIND_FLAGS="$FIND_FLAGS -name tall_\\*" ;;
48 wide)
49 FIND_FLAGS="$FIND_FLAGS ! -name tall_\\*"
50 esac
51 print -u2 "FIND_FLAGS='$FIND_FLAGS'" # diagnostic
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 numfiles=$(find $FIND_FLAGS ! -name random\* | wc -l)
58 print -u2 found $numfiles files # diagnostic
...

I run this script every 6 hours to change my backdrop. It _should_ choose
one appropriately shaped, i.e. tall ones for when the screen is rotated,
regular ones otherwise. That's why I have the "case $1 in" business.
Likewise, tall images are named tall_something.

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:

with this many backslashes it'll find
0 something having to do with filenames in $PWD
1 files named "*"
2 files named "\*"?
3+ ??

It seems I have the filenames correct:

find /export/media/backgrounds /export/media/patterns -type f -name tall_\* | wc -l
37

So, can anyone see where I've screwed up?

-- 
-eben     QebWenE01R@vTerYizUonI.nOetP     http://royalty.no-ip.org:81
1101000 1110100 1110100 1110000 0111010 0101111 0101111 1110010 1101111
1111001 1100001 1101100 1110100 1111001 0101110 1101110 1101111 0101101
1101001 1110000 0101110 1101111 1110010 1100111 0111010 0111000 0110001
-----------------------------------------------------------------------
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:06 EDT