On Sat, Mar 10, 2018 at 10:26 AM, wrote:
> Hi,
>
> I have a coyple of files on my harddisk and on a mobile usb-disc.
>
> Their names are of that pattern:
>
> something--something
>
> where 'soemthing' can be totally different from file to file and
> '' is a checksum, which does not match the checksum of the
> according file.
>
> I want to delete the files on my harddisk, which has a ''
> which matches the '' of the according file on the mobile
> harddisk.
>
> The problem arises from a line of the shellscript I wrote.
>
> # code to extract the checksum from the file and put into
> # a variable named crc
>
> if [ -f /*$crc* ] ; then
>
> # remove file on PC harddisk here
>
> fi
>
> As soon the file is not found, the script ends with an 'Not found'
> error, which '-f' is exactly for, because the expanding comes before
> the '-f'...
>
> So I need something else or a try-catch-thingy to make that work...but
> how?
>
> Or do I miss the forest for the trees here... ;)
>
> Thanks a lot for the forest in advance!
> Cheers
> Meino
>
>
>
>
>
If you were using a loop, you could do something like this:
for file in /path/to/files
do test -f $file || continue
rm $file
done
Care to post the entire script, so we could probably come up with the
right solution for you?