Reading input from user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading input from user
# 1  
Old 03-09-2008
Question Reading input from user

how do we read input from a user

e.g i want to ask a user to enter 6 sets of numbers

how do i control information from the user?

i have this.......

#!/bin/bash

echo "Please enter six numbers"
read number
echo $number >> file1


but this stops after the first number..how can i controll it to stop after say only 6 numbers have been entered.

Last edited by vadharah; 03-09-2008 at 08:09 AM..
# 2  
Old 03-09-2008
Code:
echo -n "Enter number 1: "
read num
echo -n "Enter number 2: "
read -n 1 num1
echo -n "Enter number 3: "
read -n 2 num2

I read this from the Bash Beginners Guide (Link doesn't seem to work... Google for it Smilie)

Last edited by grebbux; 03-09-2008 at 09:00 AM..
# 3  
Old 03-09-2008
Quote:
Originally Posted by vadharah
how do we read input from a user

e.g i want to ask a user to enter 6 sets of numbers

how do i control information from the user?

i have this.......

#!/bin/bash

echo "Please enter six numbers"
read number
echo $number >> file1


but this stops after the first number..how can i controll it to stop after say only 6 numbers have been entered.
have a look at this for some inspiration
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to embed data instead of reading user input from an array?

Hello, I am running under ubuntu1 14.04 and I have a script which is sending given process names to vanish so that I'd see less output when I run most popular tools like top etc in terminal window. In usual method it works. Whenever I restart the system, I have to enter the same data from... (2 Replies)
Discussion started by: baris35
2 Replies

2. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. UNIX for Dummies Questions & Answers

User input while reading from a file

I am not able to capture the user input in this script(bash).There is prompt for user input.Could some one help me capture user input while reading afile? while read line do echo "$i" path1=$line path2=`echo $line|sed s/new_dir/old_dir/` echo "Do you want to replace?";... (4 Replies)
Discussion started by: parijat guh
4 Replies

4. Shell Programming and Scripting

Reading user input...problem with tab key

Hi all, I have a little problem with my shell script (reading user input, save user input to variable, invisible characters in the log file :() printf "1. What's your file path?" /path/to/my/file read -e FILE I have invisible characters in my log file (e.g. <ESC> or ^G) when I'm... (3 Replies)
Discussion started by: splendid
3 Replies

5. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

6. Shell Programming and Scripting

reading yum user input

I am writing a script where it uses yum to install. I need to read the user input for yum ie "y or n". If the user types "y", the script should continue running. If the user types "n" then the whole script should be terminated. line1 line2 yum install package line3 line4 From above,... (5 Replies)
Discussion started by: anilcliff
5 Replies

7. Shell Programming and Scripting

Reading Standard Input

Hello, I am new to scripting. How do I read multiple lines from the command line? I know read reads one line, but if I have to read multiple lines, how should I do? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

8. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

9. Shell Programming and Scripting

reading input from a file

I am trying to read input for a C program (that expects input from the user) from a file using the shell command: progname < filename but it seems that the program considers the char '<' as the first input, hence causing an "error" in my program. I checked it with another program and it... (2 Replies)
Discussion started by: nadbar
2 Replies

10. Shell Programming and Scripting

reading from input

Hi guys , As you know normally ' read ' statement waits for the user to press enter and then terminates the input ............. Can anyone of u tell me how do i read a single character from input without waiting for the user to press enter ................ Thanks, Nagesh. (1 Reply)
Discussion started by: nageshrc
1 Replies
Login or Register to Ask a Question