Re: adding leading zeros to a filename
From: Janis Papanagnou (Janis_Papanagnou_at_hotmail.com)
Date: 01/30/05
- Next message: Chris F.A. Johnson: "Re: adding leading zeros to a filename"
- Previous message: alan_at_ljubljana.agtrz.com: "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: Chris F.A. Johnson: "Re: adding leading zeros to a filename"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 Jan 2005 21:10:40 +0100
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?
ls *.jpg 2>/dev/null | while read file; do ... ; done
will not display an error and will not iterate the loop since the read
gets an EOF; this is often the desired behaviour. If you want a separate
handling for the error case you may catch the test before you enter the
loop as a separate command; test operators are [...] and [[...]].
Janis
- Next message: Chris F.A. Johnson: "Re: adding leading zeros to a filename"
- Previous message: alan_at_ljubljana.agtrz.com: "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: Chris F.A. Johnson: "Re: adding leading zeros to a filename"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|