bash/ksh: Automatically send response to a program
Hi,
I'm working on a small script that has a sanity check to make sure the user can't easily run the script without meaning to. It has a subroutine that throws up something like this: Code:
./myscript.sh I'm currently using: Code:
{ Thanks, James |
Hi,
Take a look at the yes command. It can, repeatedly, output any string you like (man yes for details). Hope this is what you are looking for. |
Thanks druuna,
but it turns out that what I was after was just a simple pipe: Code:
echo 1 | ./myscript.sh |
Actually, back on this point. Is it possible to output "1" only once and hand back stdin to the terminal?
For my solution above, myscript.sh will get a "1" for the first request for stdin and then die when it fails to get the next request for stdin. If I used the yes command, it will answer "1" as many times as it's requested, which isn't what I want either. I seem to remember a solution to this, that looked something like a perl filehandle, for example: Code:
EOF << echo 1 |
But for the development/testing purposes, why cannot you simply comment out the "reading from input" lines in your script? Just a curiosity...
|
...or use a variable as in
[ BUGTESTING -ne 0 ] && { # run yes/no code block doSomething } # End BUGTESTING block so when you're finished testing you just prep your script with grep -v BUGTESTING myscript.sh > realscriptname.sh |
or, if you dont' want to change your shell script, write another shell script (call it spike, for example). Let this shell script output "1" to standard output. Then it simply calls "cat", which sends stuff from standard input to standard output. The script is extremely simple:
#!/bin/bash echo 1 cat Then you simply do this: spike | yourscripthere Hope this helps. |
All times are GMT -5. The time now is 05:39 PM. |