Re: [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how
> On 10 Mar 2018, at 08:26, tu...@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
Re: [gentoo-user] [OT] Kinda "try ... catch" in a shell script...how
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?
[gentoo-user] [OT] Kinda "try ... catch" in a shell script...how
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