On 17 March 2011 16:07, <[email protected]> wrote:

>  Hi,
>
> we want to exit lftp processing, when a file pattern is not matching.
>
> This exits with RC=8, if no hugo.xml file is present:
>
> find hugo.xml || exit 8;
>
>
>
> Now for patterns:
>
> glob find *.xml || exit 8;
>
> doesn’t work, if no *.xml files are there. It doesn’t exit the processing.
>
> Also:
>
> find *.xml || exit 8;
>
> doesn’t work, as it seems that find does not accept patterns.
>
>
>
> Any hint what must be done to conditionally check if multiple files are
> present on remote site and exit with a specific RC if they aren’t?
>
>
>
> Thanks,
>
> Tilo
>
>
>

Hi Tilo, Hi ListMembers.

Whenever you want to program and debug:

1) Make least assumption => Read The Fantastic Manual: You will read that
[find] return zero unless it could process normally.
enter [man find] and read EXIT STATUS chapter
So [find] will return zero if execution was normal, which does not mean that
some file was found or not.


2) For defensive/secure/debbug programming, use maximal explicit command:
use explicit arguments for [find]
find . -name "*.xml" -print


3) Develop a workaround
one solution may be testing [find] output

#!/bin/bash

# get find standard output, and skip standard error in a variable
found=$(find . -name "*.xml" -print 2>/dev/null)

# test it
if [[ ! -z ${found} ]] ; then
echo Files found:
echo ${found}
else
echo Not found
fi

--Peko

Reply via email to