Re: probleme with read command in a loop
From: laura fairhead (LoveMrsRitchie@madonnaweb.com)
Date: 04/12/03
- Next message: faeychild: "simple bash script help"
- Previous message: laura fairhead: "Re: How do I extract phone numbers from a flatfile."
- In reply to: Philippe Rousselot: "probleme with read command in a loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: LoveMrsRitchie@madonnaweb.com (laura fairhead) Date: Sat, 12 Apr 2003 07:31:43 GMT
On Fri, 11 Apr 2003 13:24:58 +0000, Philippe Rousselot <usergroup@rousselot.org>
wrote:
>Hi,
>
>I hope this this the right place to ask and sorry if not.
>
>I made a script to remove accentuated characters from a series of file name
>
>~~~~~~~~~~~~~~~
>#!/bin/bash
here add;
exec 3<&0
>find ./test_recode -name "*" | while read ff
>do
> f=$ff ;
> export f=`echo $f | tr "àäâçéèêëîïôöùüû" "aaaceeeeiioouuu"` ;
> export f=`echo $f | tr "ÂÀÄÇÉÈÊËÎÏÔÖÙÜÛ " "AAACEEEEIIOOUUU_"` ;
># export f=`echo $f | tr '[:upper:]' '[:lower:]'` ;
> if [ "$ff" != "$f" ]
> then
> echo "f avant = $ff" ;
> echo "f après = $f" ;
> echo ""
> echo -n "remplacer le fichier (y/n)? " ;
>
> read var1
replace this line with;
read var1 <&3
>
> if [ "$var1" = 'y' ] ; then
> mv "$ff" "$f"
> fi
> fi
>
>done
and here add ;
exec 3<&-
>
>Why doesn't the script stop at the read command ?
>
Because the standard input (file descriptor 0) is redirected within
the loop since your loop is at the end of a pipe-line. The default
file descriptor for 'read' to get data input is the standard input
on file descriptor 0, which is usually the terminal but here it
is the output of the find command from the previous pipe.
[ You may consider also why should you expect the 'read' command on that
line to behave any differently from the one at the start of the
while loop? Of course it has the same action - and reads another line
from the 'find' command ]
One solution is to duplicate the terminal device file descriptor outside
the pipeline and put it into fd.3 .Then use fd.3 inside the loop when you
want to read from the terminal and finally close it after the pipeline
ends - I have indicated those modifications above for you :)
byefornow
laura
>Thank you in advance
>
>Philippe
>
-- "The Bush-Blair war can be called a lot of things, but it cannot be called a war to free Iraqis. A better name is the `War of Lies,' because it is through lies that they think they can fool all the people all the time," "Freedom To Kill Iraqis" - Taher Al Adwan [ Jordanian Newspaper Columnist ]
- Next message: faeychild: "simple bash script help"
- Previous message: laura fairhead: "Re: How do I extract phone numbers from a flatfile."
- In reply to: Philippe Rousselot: "probleme with read command in a loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|