How to automatically pass 'multiple' user inputs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to automatically pass 'multiple' user inputs
# 1  
Old 08-23-2012
How to automatically pass 'multiple' user inputs

Hi Everyone,

1) I really cannot figure out how to pass multiple user inputs in a script. really need your help re this. below is the script.
-----------
Code:
#!/bin/sh
# script name: ask.sh

echo "Enter name: \c"
read NAME
echo "Your name is $NAME\n"

echo "Enter age: \c"
read AGE
echo "Your are is $AGE\n"

-----------

Now I want to automatically pass, say for example "Mickey" and "30" to the two prompts respectively but I can't figure out how. Been searching in Google but i can't find any.

So far, i can only pass 1 user input automatically such that to run ask.sh in this way:
echo "Mickey" | ask.sh

Would really appreciate all your help.

Thanks a lot!

Last edited by Franklin52; 08-23-2012 at 08:28 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-23-2012
you can pass it as arguments and read the value using $1 and $2 inside the script

Code:
 
./ask.sh "Mickey" "23"

otherwise, use it like this

Code:
 
$ cat d.sh
#!/bin/sh
read a b
echo "a value is : $a"
echo "b value is : $b"

 
$ echo "YES NO" | d.sh
a value is : YES
b value is : NO

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 08-23-2012
You can also do something like this:

Code:
./myscript.sh <<EOF
name
age
EOF

Or if you can rewrite the script, just pass them in as parameters:
Code:
#!/bin/sh

NAME="$1"
AGE="$2"

Code:
./myscript name age

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 08-24-2012
Thanks for the replies! Smilie but I can't change the script. The script is intended to ask and receive user inputs, not as as parameters. I just need to automatically pass these user inputs. Smilie
# 5  
Old 08-24-2012
Quote:
Originally Posted by mcoblefias
Thanks for the replies! Smilie but I can't change the script. The script is intended to ask and receive user inputs, not as as parameters. I just need to automatically pass these user inputs.
Then you need to use a tool like Expect
# 6  
Old 08-24-2012
Quote:
Originally Posted by mcoblefias
I can't change the script. The script is intended to ask and receive user inputs, not as as parameters. I just need to automatically pass these user inputs.
Then you need to use a tool like Expect
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to prepare a CSV table with inputs from multiple files

Hi, We have thousands of Video files and we need to prepare a table with few of it's parameters/values from their Mediainfo output. Here I have 3 sample mediainfo output text files named Vid1, Vid2 & Vid3 so on... (such we have thousands) and each file has exactly 3 lines. $ ls... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. UNIX for Beginners Questions & Answers

Password generator with user inputs

Hi, I am new to bash scripting and i wanted to make a bash script that will generate a password for a user. The user must enter his/her name and the url of the site the password is used for. And the script will generate a password with those two elements in the password. So if the url is... (0 Replies)
Discussion started by: Kvr123
0 Replies

3. Shell Programming and Scripting

Script to cp files that user inputs

Need a bash script that will ask the user: Which Files Would you like to copy? Then the user would input the filenames (space seperated, all lowercase) The script would then cp each file to /data/backup/ and also wc the files to std output. (to see how many lines each file has) Should go... (5 Replies)
Discussion started by: ajp7701
5 Replies

4. UNIX for Dummies Questions & Answers

How to give multiple inputs to a shell script

Got struck while trying to write a shell script which should automatically give input. While running a script for eg: (adpatch.sh) It Prompts for Multiple inputs like: Do you currently have files used for installing or upgrading the database installed in this APPL_TOP ? need to give... (2 Replies)
Discussion started by: abdmoha
2 Replies

5. Shell Programming and Scripting

Storing user inputs into a file

Hi, Am trying to store the user inputs into a file, but the below code will store only the first line of the values. I need to store all the user input values which may contain one or more lines. Thanks in advance. echo "please enter file names"; read name; echo $name>/tmp/test (11 Replies)
Discussion started by: rogerben
11 Replies

6. Shell Programming and Scripting

Take 10 user inputs and output to file?

I want a script that will prompt a user to enter 10 numbers and out put them into a file. This what I have so far, but isn't working. I'm guessing it's something easy I'm not seeing. Thanks for any help. #!/usr/bin/ksh echo "Enter 10 numbers" for i in 1 2 3 4 5 6 7 8 9 10 do read .... ... (8 Replies)
Discussion started by: AxlVanDamme
8 Replies

7. Shell Programming and Scripting

How to automate user's inputs.

Hi Friends, I am wrinting a shell script MorningChecks.sh which will call another script StartServer.sh. But the latter script requires user's inputs to complete. I want to automate this. So can you please let me how this can be achieved? Any help would be highly appereciated. ... (3 Replies)
Discussion started by: singh.chandan18
3 Replies

8. Shell Programming and Scripting

Scripting A Source File With User Inputs

I need to write what I thought would be a fairly simple 2-line UNIX script. It can be written PERL, csh, ksh...or whatever is easiest. The entire script will be: Begin Scipt source MySourceFile execute MyExecutable.exe End Script The problem is that MySourceFile can not be... (1 Reply)
Discussion started by: MMorrison
1 Replies

9. Shell Programming and Scripting

limiting data inputs for the user

if my user has to enter the name of months to carry out a search how can I limit the input values to only the month names and nothing else? so far my input criteria for the user is this: i would like it so the user can only enter the months in the way i have stated. otherwise they would... (11 Replies)
Discussion started by: amatuer_lee_3
11 Replies

10. Shell Programming and Scripting

Multiple Inputs

Have tried the search, but nothing resembles what I'd like to accomplish. I am attempting to write a script that will allow the user to input a list of data at the command prompt, then the data is used by another script for processing. I am allowing the user a list of 10 members in order to... (4 Replies)
Discussion started by: douknownam
4 Replies
Login or Register to Ask a Question