read from keyboard while reading from file in SHELL SCRIPTING
hi all, i'm writing a script and i'm stuck. i need to read from keyboard to ask for confirmation while im reading from a file. my code is this:
while read linea do #code echo "¿you sure? (y/n)" read answer #code done < $"agenda.dat" the problem is that stdinput has been redirected to file agenda.dat so when i do "read answer" it reads the next line from the file. any idea to solve it?? thanks |
Code:
#!/bin/bash |
hey, that's it!! thanks a lot!!!!
|
probably a cleaner one:
Code:
#!/bin/bash |
Quote:
|
Quote:
|
Like most programs, bash reads and writes from files. It labels them with numbers called file descriptors or "fd"s. By default, three files are open and are connected to the terminal
Code:
my_command 2>/dev/null The exec command can also be used to open files on file descriptors and to duplicate file descriptors. See Bourne Shell Builtins and scroll down to exec. The current file descriptors may be seen in the /proc file system Code:
c:~$ ls -l /proc/$$/fd
|
ptmx is supposedly the "pseudo-terminal master", but I'm not sure what significance it has. None of the systems I've been on has ever opened 4 like that..
Anyhow, fd 255 refers to a shell script or generally the location commands are read from. |
Quote:
Good to learn about fd 255. The system showing "4 -> /dev/ptmx" is Slackware 13.0 32-bit so likely straightforward unless mrxvt is up to something cunning. Given that fd 4 is commonly used it can easily be clobbered (and is not replaced) Code:
c:~$ exec 4<~/.bashrc |
Quote:
|
Guys you can also do that in any available fd number not just 4.
|
Reading from the keyboard without using any additional scripts
As I anderstood from the written above, the /dev/tty command calls for some kind of script.
I should read from the keyboard without additional files of scripts. Is it possible? Is it possible to alter every time between input from file or keyboard? Thanks. |
All times are GMT -5. The time now is 06:59 AM. |