[sclug] Couple of questions

Andy Arbon sclug at andrewarbon.co.uk
Sat Oct 25 09:05:34 UTC 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

The solution suggested by Spencer turned out to do the trick. Thanks..

Now I have a different problem, this time to do with shell escaping.
Escaping in Bash and I have a long and turbulent history because getting
multiple levels of escaping to work correctly in scripts has always been
a bit of a black art to me. Maybe someone can explain a better way of
doing what I want to do.

I have a script, the relevant parts being:

- ---------------
PATHS="/usr /var /bin /sbin /opt /lib /boot /etc"
EXPATHS="/usr/portage /var/wine /var/tmp/ccache /var/log /var/cache"

echo -n "Building list of files in filesystem...."
FINDEX="\( "
for path in $EXPATHS;
do FINDEX="$FINDEX-path $path\* -o "
done
FINDEX="$FINDEX-false -prune \) -o -print";
find $PATHS "$FINDEX"                            << HERE
echo "...done"
- --------------
This script should build a command line for 'find' that searches all of
the paths in $PATHS, exculding those listed in $EXPATHS and prints every
file found.

The problem is, it doesn't work ;) If I take the line marked HERE and
stick an echo at the beginning of it, I get the output (all one line):
- ----------
find /usr /var /bin /sbin /opt /lib /boot /etc \( -path /usr/portage\*
- -o -path /var/wine\* -o -path /var/tmp/ccache\* -o -path /var/log\* -o
- -path /var/cache\* -o -false -prune \) -o -print
- ------------

If I paste that into a shell everything works fine, but if I execute
that command line in the script (by not putting the echo in) it doesn't
work (find executes without any problem, but does not return the correct
results). This leads me to believe that the problem is with the escaping
that bash is doing.

I've tried a zillion combinations of different quotes and backslash
escaping to no avail. I also tried putting the line:
echo find $PATHS "$FINDEX"
in backquotes, because as far as I understand it that should produce the
same results as me copying the 'echo' output to a shell and executing
it, but that doesn't work either!

Does anyone know what I'm doing wrong?

Cheers,

Andy


|>The other problem:
|>2) I have 2 text files each containing a list of files. (say txt1 and
|>txt2). All files in txt1 are also in txt2, but there are files in txt2
|>that are not in txt1. I want to be able to separate out the files which
|>do not appear in both.. What is the best way?
|
| A combination of sort and uniq is your friend, like so
|
| 	sort txt1 txt2 | uniq -u
|
| The '-u' flag to uniq causes only the unique lines to ibe written to
| standard output.
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+Y3++X3TTUvZURBERAol7AJ9vgaKEIlXnIkV9c901UqPpKLVbeQCcDFd5
m77TjHKR6GjQgJIAyZtXDf0=
=7dr7
-----END PGP SIGNATURE-----




More information about the Sclug mailing list