bourne shell query
andrew.d.hay
mvadh at cbnews.att.com
Fri Aug 31 22:06:16 AEST 1990
In article <26DC6447.15922 at maccs.dcss.mcmaster.ca>, fred at maccs.dcss.mcmaster.ca (Fred Whiteside) writes:
[]
" what
" it should do is set the variable files to be the names of those
" articles in comp.std.c whose name (article number) is greater than or
" equal to the numeric value of the scripts first argument.
[]
"
" #!/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
how about:
#!/bin/sh
cd /usr/spool/news/comp/std/c
echo "Should ignore files with name < $1 (formerly $zots)"
for TMP in `echo * | grep -v '[a-zA-Z]'`; do if [ "$TMP" -ge $1 ]; then echo "$TMP"; fi; done
or, if you -need- to create a variable:
files=`ls -rt | grep -v '[a-zA-Z]' | while read TMP; do if [ "$TMP" -ge $1 ]; then echo "$TMP"; fi; done`
echo $files
these should also be much faster, as it relies more on shell builtins.
i'm not familiar with awk (shame on me!), but i don't see why you need
it for this...
--
Andrew Hay +------------------------------------------------------+
Ragged Individualist | You just have _N_O idea! It's the difference |
AT&T-BL Ward Hill MA | between _S_H_O_O_T_I_N_G a bullet and _T_H_R_O_W_I_N_G it! |
a.d.hay at att.com +------------------------------------------------------+
More information about the Comp.unix.shell
mailing list