Shell script to pass multiple stdin to prorgam?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to pass multiple stdin to prorgam?
# 1  
Old 04-02-2010
Shell script to pass multiple stdin to prorgam?

Running on AIX 5.3L.

I have a program "foo" written in Fortran that requires 3 levels of inputs from stdin (command prompt).

> foo
Enter Input 1: a
Enter Input 2: b
Enter Input 3: c
running foo
success!
>

How do I get a shell script to run this automatically?

> echo "a" | foo
Enter Input 1: a
The READ statement on the file (standard input) cannot be completed because the end of the file was reached. The program will stop.
>

> echo "a b c" | foo
Enter Input 1: a b c
The READ statement on the file (standard input) cannot be completed because the end of the file was reached. The program will stop.
>

> echo "a\nb\nc" | foo
Enter Input 1: a
The READ statement on the file (standard input) cannot be completed because the end of the file was reached. The program will stop.
>

I have tried almost everything: \r, \n, using printf ... etc.

How do I pass multiple levels of input through std input?
# 2  
Old 04-02-2010
Have you tried using 'here' doc? Something like:

Code:
foo <<EOF
a
b
c
EOF

# 3  
Old 04-03-2010
Code:
#!/bin/ksh
> answer.txt
for val in 1 2 3
do
      echo "Value$val:\c"
      read value
      echo "$value\r" >> answer.txt  # need cr+lf
      #echo "$value" >> answer.txt    # only lf
done
someprog < answer.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with the Script to pass stdin in run time

I have put a script inside bash_profile of user "root". That script executes when we do "sudo su -" and prompts with a question : "Why are you logginf as root?" and users have to pass the reason then they get prompt. Inside script we have used "read -p input" to take input from user. I am a... (3 Replies)
Discussion started by: shekhar_4_u
3 Replies

2. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

3. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

5. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

6. Shell Programming and Scripting

call another shell script and pass parameters to that shell script

Hi, I basically have 2 shell scripts. One is a shell script will get the variable value from the user. The variable is nothing but the IP of the remote system. Another shell script is a script that does the job of connecting to the remote system using ssh. This uses a expect utility in turn. ... (2 Replies)
Discussion started by: sunrexstar
2 Replies

7. Shell Programming and Scripting

reading from stdin in a shell script

Hello, I've managed to get my .procmailrc file to work. At least it triggers a script which creates a file. But the file is empty. How do I get at the data that's been piped? I've done much creative googling to no avail. I belive it should be in stdin, but I can't figure out how to access... (4 Replies)
Discussion started by: mmesford
4 Replies

8. Shell Programming and Scripting

Cannot redirect to STDIN in a shell script

I am unable to use STDIn redirection with < (commands) When I do the following, both approaches work and give the same results: 1. $ printf "aaa\nbbb\n" > file1 $ printf "111\n222\n" > file2 $ cat file1 file2 aaa bbb 111 2222. $ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n") aaa... (8 Replies)
Discussion started by: metaltree
8 Replies

9. Shell Programming and Scripting

How to pass stdin to java?

I have a java program that uses jtidy to read from stdin and write to stdout. I want to use this with vi or vim. The problem is that the java class paths are pretty ugly. How do I write a bash script that looks like this: ./jtidy.sh <inputfile.html >outputfile.html and has the same effect... (0 Replies)
Discussion started by: siegfried
0 Replies

10. Shell Programming and Scripting

Pass multiple variables to SQL script

I am trying to close of multiple users in an Oracle database. Each users has records in multiple tables what I need to do is use a script that call each SQL seperately passing either CLI arguments or gathered arguments from the users during run time. ## Accept variable(s) from the command line... (1 Reply)
Discussion started by: jagannatha
1 Replies
Login or Register to Ask a Question