passing argument to shell script that reads user inputs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing argument to shell script that reads user inputs
# 1  
Old 04-09-2009
passing argument to shell script that reads user inputs

Hi,
Lets say I have a script "ss" which does this

read abc
echo $abc
read pqr
echo $pqr

Now if I want to pass and argument to only "abc" how do I do it.
If I do

echo "somevalue" | ss, it does not prompt for pqr and its value comes out as blank.

Any help is appreciated

Thanks
P
# 2  
Old 04-09-2009
Try this:

Code:
read abc
echo $abc

read pqr < "/dev/tty"
echo $pqr

Regards
# 3  
Old 04-09-2009
I thought of trying heretext as follows:
Code:
./ss << EEOOFF
abc
EEOOFF

Where the first read will get the value abc, the second read waits for user input.
# 4  
Old 04-09-2009
@Franklin52:
Thanks for your reply. But I can't modify the script. All I have to play with is how the argument is passed Smilie

P
# 5  
Old 04-09-2009
@Tony:
I tried that, but it doesnt wait for the prompt at the second instance. It prints a blank value

P
# 6  
Old 04-10-2009
Worked for me In Linux in bash.
# 7  
Old 04-10-2009
Try this:

Code:
(echo "abc-value"; cat -) | uncooperative-script

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script that reads a file

I have below script to read a file line by line. How can I ensure that the loop will stop after last line. #!/bin/bash while read -r mod ver tarball; do echo $mod done < taskfile.txt (4 Replies)
Discussion started by: aderamos12
4 Replies

2. Shell Programming and Scripting

Passing user argument

Hi all: I'm trying to pass an argument to a command but it's being difficult. #!/bin/bash set -xv if ; then echo "More than 1 argument entered" echo "Please enter a month using 3 character names, ie, Jan, Mar, Apr, Dec" && exit 1 fi if ; then echo "Please enter a month using... (2 Replies)
Discussion started by: raggmopp
2 Replies

3. Shell Programming and Scripting

passing argument in script?

hi, I want to implement some function to perform following task if ; then $TEXT = "Data_0" else $TEXT = $1 fi if ; then $Lines = 45 else $Lines = $2 fi Kindly suggest, thanks (11 Replies)
Discussion started by: nrjrasaxena
11 Replies

4. Shell Programming and Scripting

Passing argument from Java to Shell script

Hi All, I want to pass array of argument from Java to a shell script.I can use process builder api and its exec() method to call the script,but the question is how to receive the parameter in the script. Thanks in advance ---------- Post updated at 10:00 PM ---------- Previous update was... (1 Reply)
Discussion started by: Abhijeet_Atti
1 Replies

5. Shell Programming and Scripting

passing either of argument, not both in shell

Hi, I have a requirement to work on script, it should take either of arguments. wrote it as below. #!/bin/bash usage() { echo "$0: missing argument OR invalid option ! Usage : $0 -m|-r|-d } while getopts mrdvh opt; do case "$opt" in m) monitor_flag=monitor;;... (1 Reply)
Discussion started by: ramanaraoeee
1 Replies

6. Shell Programming and Scripting

Passing argument to a script while executing it within current shell

Hi Gurus, I have written a script set_env.ksh to which I pass an argument and set the oracle login credentials based on the argument I pass. The script has code as below. ORACLE_SID=$1 DB_SCHEMA_LOGON=$DB_SCHEMA_USER/$DB_SCHEMA_PASSWORD@$ORACLE_SID; export DB_SCHEMA_LOGON; echo... (3 Replies)
Discussion started by: Sabari Nath S
3 Replies

7. UNIX for Dummies Questions & Answers

Passing command output as an argument to a shell script

Hi, I have a very small requirement where i need to pass command output as an argument while invoking the shell script.. I need to call like this sh testscript.sh ' ls -t Appl*and*abc* | head -n 1' This will list one file name as ana argument.. I will be using "$1" in the shell... (2 Replies)
Discussion started by: pssandeep
2 Replies

8. UNIX for Dummies Questions & Answers

Passing command line argument between shell's

Hi, I am facing a problem to pass command line arguments that looks like <script name> aa bb "cc" dd "ee" I want to pass all 5 elements include the " (brackets). when I print the @ARGV the " disappear. I hope I explain myself Regards, Ziv (4 Replies)
Discussion started by: zivsegal
4 Replies

9. Shell Programming and Scripting

Help in passing array of inputs to C program using script?

Hi, I have a file input which has 1000 data inputs of array elements. I would like to pass this to a C program one line at a time as input automatically. Anyone know how I could use "sed" to perform this? Appreciate alot. Thanks. (1 Reply)
Discussion started by: ahjiefreak
1 Replies

10. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies
Login or Register to Ask a Question