How to provide stdin from one script to another script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to provide stdin from one script to another script?
# 1  
Old 08-13-2011
How to provide stdin from one script to another script?

Dear all

I have a scripts call "script.sh", that I need to provide 3 params from stdin
i.e.
Code:
# script.sh

Please input first name : Hello
Please input last name : Kitty
Please input sex : F

Without changing script.sh, I want to write another script call "script_slient.sh", that will read the first_name, last_name and sex params from command line.

Code:
# script_slient.sh Hello Kitty F
first_name=$1
last_name=$2
sex=$3
# In this script, how can I call script.sh and pass the three params to it?

Thank you.
Valentino
# 2  
Old 08-13-2011
Try this technique (it's possible this wouldn't work - it depends on how your first script reads values):
Code:
cat script1
read a; echo a=$a
read b; echo b=$b
read c; echo c=$c

cat script2
{ echo $1
echo $2
echo $3 ; } | ./script1

./script2 x y z
a=x
b=y
c=z

# 3  
Old 08-15-2011
Use what is called a "here document".

script_silent.sh:
Code:
#!/bin/ksh

script.sh <<EOF
$1
$2
$3
EOF

Actually this doesn't work as expected. When I ran this it throws an ioctl error. hmmm. My apologies for not testing something I thought was a simple answer!

Last edited by gary_w; 08-15-2011 at 11:27 AM..
# 4  
Old 08-15-2011
It should not throw an ioctl error. What does it actually say?
# 5  
Old 08-15-2011
Thanks for taking a look, this is interesting. Good lesson to always test before posting code no matter how simple you think it is! I'm running on Solaris by the way.

script.sh:
Code:
#!/bin/ksh
echo "first: \c"
read first
echo "Last: \c"
read last
echo "sex: \c"
read sex

echo "You entered: $first $last $sex"

script_silent.sh:
Code:
#!/bin/ksh

script.sh <<EOF
$1
$2
$3
EOF

Output:
$ script_silent.sh Hello Kitty F
stty: : Inappropriate ioctl for device
first: Last: sex: You entered: Hello Kitty F
$

Note: if run using ksh93 (/usr/dt/bin/dtksh on our machine) I do not get the stty error, but the output line is the same.
# 6  
Old 08-16-2011
It's trying to do terminal calls on a pipe, looks like. That's poor practice, they should call isatty() first to check. If it actually works and just looks funny, you can ignore the error. Try unsetting TERM, maybye that'll convince it not to try doing things to a non-terminal.
# 7  
Old 08-16-2011
Unsetting TERM did stop the error. Interesting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use stdin as argument for script?

Say I had an extremely simple script called testScript.sh: #!/bin/sh echo $1 and I invoked it as: source testScript.sh <<< x or source testScript.sh <<< inputFile.txt When I do the above the values don't appear in the echo statement, and I know that is because in the echo... (5 Replies)
Discussion started by: steezuschrist96
5 Replies

2. Shell Programming and Scripting

Passing stdin value into a script that is called from another script

I'm trying to automatically pass user input values into a script that is being called from another script, below is my current script and I added a comment next to the script where it asks user to enter input value. Thanks, mbak #!/bin/ksh echo " Adding disks for DB server then Enter YES... (2 Replies)
Discussion started by: mbak
2 Replies

3. Emergency UNIX and Linux Support

How to provide password for rsync in shell script?

Hi, i want to call the rsync in a shell script so that i can run it in background by passing the password within script itself. Can any one please let me know how can i provide the password in the shell script itself so that rsync will read the password when promted by the script. Its very... (11 Replies)
Discussion started by: Little
11 Replies

4. Shell Programming and Scripting

Can any one provide shell script for this ...

• With this script, users will be able to o Enter into the recycle bin mode. During this mode, all files deleted will be sent to the recycle bin. The recycle bin will be common to all users. o View contents of the recycle bin (his/her file(s) only). o Retrieve a particular file from the recycle... (3 Replies)
Discussion started by: bhavana busetty
3 Replies

5. Shell Programming and Scripting

How to provide auto inputs for a sub-script within a script?

Hi All, I am writing a shell script. #!/bin/bash cat /etc/hosts mkdir -p /var/tmp mount 113.123.35.37:/vol/vol615/syb /var/tmp In above script I am trying to add below predefined script/command (/var/tmp/db_tools) This command in turn ask for user input, which will be always option... (17 Replies)
Discussion started by: madhur.baharani
17 Replies

6. Shell Programming and Scripting

Provide Password using to the application using the shell script

Hello, I have a requirement to shut down and start up my application on different environments (Dev, QA and Prod). I have around 24 servers. I have to login to each server manually for shutinng down the application. I wrote a shell command on each server and I am invoking those shell... (2 Replies)
Discussion started by: GDSR Raju
2 Replies

7. Shell Programming and Scripting

Script to provide percentages?

so i'm have been stifled here inn my attempts at this. i need to calculate an unusual figure. what is the percentage difference between 400 and 3? usually, to get the percentage, you just divide the smaller number by the bigger number. then multiply the answer by 100. in this case... (10 Replies)
Discussion started by: SkySmart
10 Replies

8. Shell Programming and Scripting

Please provide me with a KSH script.

Hi frnds Im new to unix. I have an xml like the following: <?xml version="1.0"?> <serviceFeeDetail> <Data> <totalAmount>40</totalAmount> </Data> <serviceFee> <invoiceBillGrpNbr>1</invoiceBillGrpNbr> <serviceFeeLineItem> <billLineNbr>1</billLineNbr> ... (2 Replies)
Discussion started by: balesh
2 Replies

9. Shell Programming and Scripting

Provide input in sqlplus script

Hi guys. I m creating scripts which input multiple value , inside sqlplus script when it prompt/accept do anybody know how to provide multiple value inside sqlplus script when it prompt. like, enter value for first: enter value for second: enter value "save file as " : I m try... (11 Replies)
Discussion started by: tapia
11 Replies

10. Shell Programming and Scripting

provide a user password from a script

Hi all, passwd <username> < /var/adm/passwd.txt cat /var/adm/passwd.txt abcd1234 abcd1234 when I run this from the script, it comes with: New password: It is not able to pick from the location /var/adm/passwd.txt. thanks in advance. (6 Replies)
Discussion started by: solaix14
6 Replies
Login or Register to Ask a Question