* [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how
@ 2018-03-10 8:26 tuxic
2018-03-10 11:59 ` Alexander Kapshuk
2018-03-10 13:27 ` Stroller
0 siblings, 2 replies; 3+ messages in thread
From: tuxic @ 2018-03-10 8:26 UTC (permalink / raw
To: Gentoo
Hi,
I have a coyple of files on my harddisk and on a mobile usb-disc.
Their names are of that pattern:
something-<checksum>-something
where 'soemthing' can be totally different from file to file and
'<checksum>' 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 '<checksum>'
which matches the '<checksum>' 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 <path to the mount point of the mobile disk>/*$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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how
2018-03-10 8:26 [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how tuxic
@ 2018-03-10 11:59 ` Alexander Kapshuk
2018-03-10 13:27 ` Stroller
1 sibling, 0 replies; 3+ messages in thread
From: Alexander Kapshuk @ 2018-03-10 11:59 UTC (permalink / raw
To: Gentoo mailing list
On Sat, Mar 10, 2018 at 10:26 AM, <tuxic@posteo.de> wrote:
> Hi,
>
> I have a coyple of files on my harddisk and on a mobile usb-disc.
>
> Their names are of that pattern:
>
> something-<checksum>-something
>
> where 'soemthing' can be totally different from file to file and
> '<checksum>' 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 '<checksum>'
> which matches the '<checksum>' 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 <path to the mount point of the mobile disk>/*$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?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how
2018-03-10 8:26 [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how tuxic
2018-03-10 11:59 ` Alexander Kapshuk
@ 2018-03-10 13:27 ` Stroller
1 sibling, 0 replies; 3+ messages in thread
From: Stroller @ 2018-03-10 13:27 UTC (permalink / raw
To: gentoo-user
> On 10 Mar 2018, at 08:26, tuxic@posteo.de wrote:
> ...
>
> 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... ;)
I don't get that at all with this snippet:
$ cat test.sh
#!/bin/bash
if [ -f foo* ] ; then
echo "foo exists"
fi
$
This makes me suspect you've got `#!bash -x` (or -e?) as your first line, or something.
When you encounter a problem you don't understand, create the most minimal program you can to reproduce the problem. If you can't reproduce it, add to it one step at a time until it becomes what you're trying to do.
Stroller
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-10 13:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-10 8:26 [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how tuxic
2018-03-10 11:59 ` Alexander Kapshuk
2018-03-10 13:27 ` Stroller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox