standard redirections
Hi all,
I would like to run an interactive script, but I'm a bit lost. Is there any way to read a value from the keyboard when the standard input has been assigned to a file into a sh-script? It means, into a script I have a while loop, like:
cat $file | while read line;do
[commands]
echo "Continue(y/n)?"
read cont
if [ "$cont" = "n" ];then exit 1;fi
[more commands]done
In this way, cont is read from $file. Does anybody know how I could redirect again de standard input?
Thanks in advance for your help!
Signature · 8 lines
Best regards, César mailto:[email protected] - To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
On most UNIX systems /dev/tty is the name for the "controlling terminal" of the process (i.e. the one where you typed in the command -- this is not a precise definition of controlling terminal of course) so if you arrange to read from /dev/tty you will be talking to the terminal not the file. Look at man 4 tty for another description of this.
read cont < /dev/tty
works for me with bash.
John.
Quoted 27 lines · César Soler
Hi all,
I would like to run an interactive script, but I'm a bit lost. Is there any way to read a value from the keyboard when the standard input has been assigned to a file into a sh-script? It means, into a script I have a while loop, like:
cat $file | while read line;do
[commands] echo "Continue(y/n)?" read cont if [ "$cont" = "n" ];then exit 1;fi [more commands]done
In this way, cont is read from $file. Does anybody know how I could redirect again de standard input?
Thanks in advance for your help!
--
Best regards,
César mailto:[email protected]
Quoted 5 lines
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 6 lines · John Hallam
On most UNIX systems
/dev/ttyis the name for the "controlling terminal" of the process (i.e. the one where you typed in the command -- this is not a precise definition of controlling terminal of course) so if you arrange to read from/dev/ttyyou will be talking to the terminal not the file. Look at man 4 tty for another description of this.
Quoted 6 lines
read cont <
/dev/ttyworks for me with bash.
John.
Thank you very much for your help and your time, as well as Tims'. This also works in my case!
- -----------------------------------------------------------------------------
César Soler mailto: [email protected]
PGP KeyID: 0x179DAD53 at >>>>>>>>>>>>>>>>>>>>>>> http://search.keyserver.net/
- -----------------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8
iQA/AwUBPOa3bRXze/0Xna1TEQKHiwCeNaVPWlan7TZvLPNvzWnKpwey1DEAoIUL UfYc46EQApS0SwTe1X4qaNVf
=YCO4
-----END PGP SIGNATURE-----
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html