bourne shell query

Neil Smithline smithln at honeydew.cs.rochester.edu
Sat Sep 1 05:28:56 AEST 1990


In article <26DC6447.15922 at maccs.dcss.mcmaster.ca>, fred at maccs (Fred Whiteside) writes:
>
>...
>
>#!/bin/sh
>cd /usr/spool/news/comp/std/c
>zots=$1
>echo "Should ignore files with name < $zots"
>files=`ls -rt * |grep -v '.*[a-zA-Z].*' | awk $1 '>=' $zots {print}`
>echo $files
>

The best way to figure this out is to go into the shell and start
typing.  To find the problem, run /bin/sh and go into the correct
directory.  Once there try the command
	ls -rt *
and see if this produces the correct output - if it does see what
happens if you add the grep.  If this works try the awk.  You'll see
that this causes awk to bail out.  Even if you reduce the awk
statement to
	awk $1 '>=' 1 {print}
awk still gives you an error message.  From this you can conclude that
this has nothing to do with the rest of the line and resort to the old
awk man page.  If you quote the arguments, all works fine.  That is:
	awk '$1 >= 1 {$print}'
works.  Now to add the shell variable $zots to this just insert it
*unqoted* into the line
	zots=1
	awk '$1 >= '$zots' {print}'
Once you have this just replace the awk statement in your program with
the above line and all works properly.

In general, I find that complex shell quoting is best solved with an
inside-out approach, get the inside to work and then add the next
level of quotes to that - of course, as you get better you need to
do less and less of this - Neil
-- 
========================================================================
Neil Smithline
ARPA:    smithln at cs.rochester.edu
UUCP:    ..!rutgers!rochester!smithln 



More information about the Comp.unix.shell mailing list