Article View: comp.unix.shell
Article #981Re: bourne shell query
From: Neil Smithline
Date: Fri, 31 Aug 1990 19:28
Date: Fri, 31 Aug 1990 19:28
41 lines
2177 bytes
2177 bytes
In article <26DC6447.15922@maccs.dcss.mcmaster.ca>, fred@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@cs.rochester.edu
UUCP: ..!rutgers!rochester!smithln
Technical Details
Message-ID:
<1990Aug31.192856.9129@cs.rochester.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!rochester!smithlnReferences:
<26DC6447.15922@maccs.dcss.mcmaster.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!rochester!smithln From: smithln@honeydew.cs.rochester.edu (Neil Smithline) Newsgroups: comp.unix.shell Subject: Re: bourne shell query Message-ID: <1990Aug31.192856.9129@cs.rochester.edu> Date: 31 Aug 90 19:28:56 GMT References: <26DC6447.15922@maccs.dcss.mcmaster.ca> Sender: smithln@cs.rochester.edu (Neil Smithline) Reply-To: smithln@honeydew.cs.rochester.edu (Neil Smithline) Organization: University of Rochester Lines: 41 In-Reply-To: fred@maccs.dcss.mcmaster.ca (Fred Whiteside)