Re: adding leading zeros to a filename
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 01/30/05
- Next message: John DuBois: "Re: select line from file, and then the next line a week later"
- Previous message: Janis Papanagnou: "Re: adding leading zeros to a filename"
- In reply to: alan_at_ljubljana.agtrz.com: "Re: adding leading zeros to a filename"
- Next in thread: Stephane CHAZELAS: "Re: adding leading zeros to a filename"
- Reply: Stephane CHAZELAS: "Re: adding leading zeros to a filename"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jan 2005 22:15:27 GMT
On Sun, 30 Jan 2005 at 19:37 GMT, alan@ljubljana.agtrz.com wrote:
> On 2005-01-28, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
>> rupert wrote:
>> > Basically I know nothing about shell scripting. I'm guessing I can
>> > write such a beast that will list the contents of a directory
>>
>> for file in *.jpg; do
>> ...
>> done
>>
>> or
>>
>> ls *.jpg | while read file; do
>> ...
>> done
>
> How do you handle the case where directory contains no *.jpg.
>
> I get an error. Is there an idiom for the test?
You can test before the loop:
set -- *.jpg
[ -f "$1" ] &&
for file
do
: do whatever with "$file"
done
Or you can test within the loop:
for file in *.jpg
do
[ -f "$file" ] || continue
: do whatever with "$file"
done
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: John DuBois: "Re: select line from file, and then the next line a week later"
- Previous message: Janis Papanagnou: "Re: adding leading zeros to a filename"
- In reply to: alan_at_ljubljana.agtrz.com: "Re: adding leading zeros to a filename"
- Next in thread: Stephane CHAZELAS: "Re: adding leading zeros to a filename"
- Reply: Stephane CHAZELAS: "Re: adding leading zeros to a filename"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|