Multiple input on same line?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Multiple input on same line?
# 1  
Old 03-01-2011
Multiple input on same line?

Hey all. I am trying to ask the user to enter two pieces of input that I will assign to variables all in one line. So for instance... I ask this:

"Please enter your name and age:"

With the following command I can do this on seperate lines. How can I do it all on one line?

Here is what I started with:

Code:
read -p  "Enter your name: " name
read -p  "Enter your age: " age

How can I do this on one line?

Using BASH
# 2  
Old 03-01-2011
Please remove
# 3  
Old 03-01-2011
Just figured out part of what I wanna do by doing this:

Code:
read -p  "Enter your name and age: " name age

Actually just thought of a part two to this. If this was a file named "bio" how could I set this up so that when I run bio at the command prompt I could type bio "name" "age" when running the file so it will run with these variables already assigned. Basicall I want to assign variables when file executes. I know Im asking alot here!

---------- Post updated at 11:52 AM ---------- Previous update was at 11:50 AM ----------

Why do you want my post removed out of curiosity?
# 4  
Old 03-01-2011
No, I wanted my post removed, not yours. You could do it by adding to your script variables $1 and $2, where in
Code:
bio.sh firstarg secondarg

firstarg becomes $1 and secondarg becomes $2, understand?

---------- Post updated at 12:20 PM ---------- Previous update was at 12:17 PM ----------

To clarify, whatever parameters you run the script with are called arguments, inside of your script the first argument is referred to by $1, the second as $2 and so on.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Shell Programming and Scripting

Multiple file input

Once a time, I did see a way to multiply a file input in bash, but have forgotten how it was done. Eks. awk 'FNR==NR {a++;next} ($2 in a) {print $2}' file file Here you need file two times. I seen it some like this awk 'FNR==NR {a++;next} ($2 in a) {print $2}' 2&file (16 Replies)
Discussion started by: Jotne
16 Replies

3. Shell Programming and Scripting

Command line multiple input

I'm using the below to get multiple input from USER and it is working, is there any better way in awk array single liner? echo "Enter Multiple input (Ctrl+d to exit)" >output while read A do echo "$A" >>output done (3 Replies)
Discussion started by: Roozo
3 Replies

4. Shell Programming and Scripting

Curl - input line by line from text file

Hi, I've got a text file with hundreds of lines I need to upload to an API via curl, one by one. The text file is like: 2012-08-01 10:45,124 2012-08-02 10:45,132 2012-08-03 10:45,114 I want to get curl to go through the text file sending a post for each line. like: curl --request... (0 Replies)
Discussion started by: emdeex
0 Replies

5. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

6. UNIX for Advanced & Expert Users

Input for multiple files.

Hi, I am trying to come up with a script, and would like the script to pick all the files place within a folder and interactive take my yes/no before processing within the command. Could you someone help me in modifying the script : #!/bin/bash # LDIF_FILES="File Name" for MY_FILE... (5 Replies)
Discussion started by: john_prince
5 Replies

7. Shell Programming and Scripting

sed to read line by line and input into another file

I have two files. Fileone contains text string one text string two text string three Filetwo contains Name: Address: Summary: Name: Address: Summary: Name: Address: Summary: I would like to use sed to read each line of file one and put it at the end of the summary line of file... (3 Replies)
Discussion started by: dolacap
3 Replies

8. Shell Programming and Scripting

Input 2 files, calculate diffs line by line

Hi I am new to Unix and need help with the following (to you all I'm sure) simple task. I am trying to output the differences between previous snaphots of various filesystem sizes to the present sizes. I have three files (e.g.) : file 1 file 2 file 3 10 100 /var... (4 Replies)
Discussion started by: bigbuk
4 Replies

9. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies

10. Shell Programming and Scripting

How to prompt for input & accept input in ONE line

hi, am a new learner to shell programming. i have a script which will prompt for user to key in their name & display their name afterwards. script ===== echo "Pls enter your name:" read name echo "Your name is $name." output ===== Pls enter your name: Bob Your name is Bob. what... (2 Replies)
Discussion started by: newbie168
2 Replies
Login or Register to Ask a Question