Sorry, newbie here. I have the following shell script which basically executes the sh-n-body.i686 program a specified number of times. However, before the sh-n-body.i686 begins its calculations it prompts for input from the user. In this case the user would have press ". return" and sh-n-body.i686 will continue running. However, I just want the code to run about 100 times without having to enter . return. How can I modify the shell script so that it takes care of the prompt( . return).
#!/bin/sh
COUNTER=0
while [ $COUNTER -lt 100 ]; do
./sh-n-body.i686 56 3 32 0.02 1 -2 | grep "longest shadow"
let COUNTER=COUNTER+1
done
Do you have access to the source code, or perhaps even the ability to change it? Perhaps it's reading /dev/tty rather than stdin, or something similarly inconvenient.
The ./sh-n-body.i686 script is expecting the input, not the script that you showed in the example.
Somewhere in the script, there is probably a 'read' statement. Looks like this perhaps:
read value
When you enter your input, it gets stored in $value.
Only thing you have to do is manually assign your input to $value, like so:
I don't know if it makes a difference but ./sh-n-body.i686 is a c file not a shell script.
Quote:
Originally Posted by lionatucla View Post
the above code just results in a . after the sh-n-body has finished. I still get the prompt
The ./sh-n-body.i686 script is expecting the input, not the script that you showed in the example.
Somewhere in the script, there is probably a 'read' statement. Looks like this perhaps:
Code:
read value
When you enter your input, it gets stored in $value.
Only thing you have to do is manually assign your input to $value, like so: