Passing input to script using another script

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Passing input to script using another script
# 1  
Old 12-19-2016
Passing input to script using another script

I need a script to pass the input to another script.
eg: I need a script to provide input to the sample script becuase my input value are constant.
Code:
$./sample.sh
PLease provide the comment:<input>
date:<date>
select the option:<1/2>


Last edited by Scrutinizer; 12-19-2016 at 12:35 AM.. Reason: code tags
# 2  
Old 12-19-2016
You are saying the answers are always the same. And you do not want to hard code them in the script because it may need to change someday.

You can use a here document:
Assume your script is named script.sh
Code:
#!/bin/bash
# example here document
./script.sh << EOF
comment, comment, comment 
`date`
1
EOF

The stuff between the EOF words is what would be typed on the keyboard.
EOF can be any combination of symbols that are not any valid UNIX or shell keyword or command.
Example -
Code:
myprog << !
stuff
!

! is not any valid keyword or command

NOTE: !! the EOF or whatever you use must match exactly on the first line and the end. Plus the last EOF has to be in column 1 - the leftmost column.
If you want to have the last EOF somewhere for easier reading use a dash (red so you see it) on line #1 before the EOF or ! or whatever.
Code:
myprog <<-EOF
stuff
       EOF

You absolutely cannot stick random "EOF" some place else in the code, other than where the true end is, when you do this. It will be treated as the end and you will get errors.

Last edited by jim mcnamara; 12-19-2016 at 01:02 AM..
# 3  
Old 12-19-2016
Why not redirect stdin from a file, then?

Code:
./sample.sh <my_input

with my_input being
Code:
<input>
<date>
<1/2>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Passing variable from called script to the caller script

Hi all, Warm regards! I am in a difficult situation here. I have been trying to create a shell script which calls another shell script inside. Here is a simplified version of the same. Calling Script. #!/bin/ksh # want to run as a different process... (6 Replies)
Discussion started by: LoneRanger
6 Replies

3. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the 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 |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

4. Shell Programming and Scripting

Passing string as a input parameter for a shell script

Hi i have a shell script which needs a string as an input parameter. How to pass the string param as an input? In command line am running the script. for e.g., a="who is a buddy?" sh sample.sh $a Inside the script i get this input param as $1 but only the value "who" is accepted... (12 Replies)
Discussion started by: vidhyaS
12 Replies

5. Shell Programming and Scripting

Passing variable from shell script to python script

I have a shell script main.sh which inturn call the python script ofdm.py, I want to pass two variables from shell script to python script for its execution. How do i achieve this ????? Eg: main.sh a=3 b=3; c= a+b exec python ofdm.py ofdm.py d=c+a Thanks in Anticipation (4 Replies)
Discussion started by: shashi792
4 Replies

6. Shell Programming and Scripting

call a script from another script passing parameters

I want to call script2 from script1 passing parameters. I want to read the parameters list in script1, check the local directory (for example - lpath1|lpath2|lpath3|lpath4|lpath5|) for the existance of files and set the` lcount` to the number of files in this folder (`... (2 Replies)
Discussion started by: Lenora2009
2 Replies

7. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

8. UNIX for Advanced & Expert Users

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now I... (2 Replies)
Discussion started by: venu_eie
2 Replies

9. Shell Programming and Scripting

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now... (1 Reply)
Discussion started by: venu_eie
1 Replies

10. Shell Programming and Scripting

passing parameter from Shell-script to Sql-script

Dear Friends, Please help me to achieve the following: I want to pass one parameter from Shell-script to Sql-script. Example: My ShellScript.sh is calling report.sql like this: /bin/sqlplus /reports.sql And My report.sql is calling many Stored-Procedures like this: exec... (0 Replies)
Discussion started by: subodhbansal
0 Replies
Login or Register to Ask a Question