On Wed, 3 Aug 2005, Mike Branda wrote:
> On Wed, 2005-08-03 at 17:13 -0400, Eben King wrote:
> > On Wed, 3 Aug 2005, Mike Branda wrote:
>
> > > if [ -e $logdir/$file1 ] && [ -e $logdir/$file2 ]
> >
> > You could maybe speed that up, dunno:
> >
> > if [[ ( -e $logdir/$file1 ) && ( -e $logdir/$file2 ) ]]
> >
> > With [], if $foo contains a space or other "bad" character, you have to
> > write "$foo". Not so with [[]].
>
> I just figured out that if [ -e $logdir/$file1 ] is what's doing it.
> The idea was to test for the existance of one or both files and run
> commands accordingly. So it's trying to test the expansion of both
> files.
>
> + '['
> -e /home/wacky1/cumulativelog/access.log.2005-07-01.gz /home/wacky1/cumulativelog/access.log.2005-08-01.gz ']
>
> gotta love that -x flag of bash. Anyway, how do I tell it to care only
> if a .gz file exists and not expand all of $file1 in the statement?
Well, if you're going to do something like
for file in *.gz ; do
# stuff
done
anyhow, then you could put
[[ -e $file ]] || exit
inside it. If there are no *.gz files, the "*" won't be expanded and the
loop will be run (once) with file="*.gz". Usually that won't exist, so in
that case it aborts.
The other code I can think of is something like
[[ $(ls -1 *.gz 2> /dev/null | wc -l) -eq 0 ]] && exit 1
before everything. I think checking for the existence of each file takes
less time than listing and counting them all, but you should do timings if
it's critical.
-- -eben ebQenW1@EtaRmpTabYayU.rIr.OcoPm home.tampabay.rr.com/hactar Are you confident that you appear to be professional in your electronic communication? Consider this: A: No Q: Can I top post? from nick@xx.co.uk----------------------------------------------------------------------- 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 - 19:41:54 EDT