Sponsored Content
Top Forums Shell Programming and Scripting How to get the user input recursively until the user provides valid input Post 302632383 by i.srini89 on Monday 30th of April 2012 03:01:25 AM
Old 04-30-2012
How to get the user input recursively until the user provides valid input

Hi,

Code:
echo "Enter file name of input file list along with absolute path : "
read inputFileList
 
if [ -f $inputFileList ]
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 then "file does not exist" is given and the program is done.
How to prompt the user for input continuously untill the user enters the proper file name with absolute path without exiting the program i.e. "Enter file name of input file list along with absolute path : " prompt should be given as long as the user gives a invalid filename.

Using a loop is one way. any other way or better ways?
Thanks,
Srini
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting user input

I am trying to create a shell (ksh) which has two "read" commands, one which reads a line from a file and another which is inside a loop that reads user input from a keyboard. However, the "read" command inside the loop uses the input from the file and it does not get the user input from keyboard.... (3 Replies)
Discussion started by: stevefox
3 Replies

2. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: vadharah
2 Replies

3. Shell Programming and Scripting

tcsh and user input

Here is my script: echo "var 1:" read varone echo "$varone" When I run in via ksh the script runs successfully. However when I run it via tcsh I get "varone: Undefine variable" Does the name command not work with tcsh or do I need some additional modification? Is there a way to get... (1 Reply)
Discussion started by: bonesy
1 Replies

4. Shell Programming and Scripting

Valid input compared with input

Hi everyone, I cant seem to figure this out for the life of me. Basically, I have two arrays.. sub init { use Getopt::Long; use Data::Dumper; my @selections = (); my @valid_options = ( "vaild1", "valid2" ); GetOptions( "input=s" =>... (2 Replies)
Discussion started by: ckozler
2 Replies

5. Shell Programming and Scripting

user input in perl?

Please tell me how to write a perl script that asks the user to enter words and that passes them to a variable. In bash, the "read" command would achieve such user interaction. #!/bin/bash read -p "Enter files: " vFiles However, I am looking for perl version of something equivalent... (2 Replies)
Discussion started by: LessNux
2 Replies

6. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

7. Shell Programming and Scripting

How to check the user input to be valid using shell script?

How to check the user input to be valid using shell script? The valid input is in the format like as follows. 1. It can only have r,w,x or a hyphen and nothing else. 2. ensure the r, w, x are in the correct order. for example: rwxr-xr-x is a valid format. Thanks (5 Replies)
Discussion started by: hyeewang
5 Replies

8. UNIX for Dummies Questions & Answers

Clumsy user input

The (longer) script that I am working on does something like this: #!/bin/bash while true do clear sleep 1 shuf -i1-2 -n1 sleep .1 clear echo "Press 1 if you saw a 1. Press 2 if you saw a 2." read -s -n1 RESPONSE done If the user accidentally presses two... (1 Reply)
Discussion started by: darwin_886
1 Replies

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

10. Shell Programming and Scripting

Controlling user input

I'm trying to use a bash script for a psych experiment that involves listening to sound files and responding. If I have something like the code below, how can I make sure that a key press is assigned to RESPONSE only after the second echo statement? for i in 1 2 3; do echo "Ready?" sleep 2 ... (10 Replies)
Discussion started by: darwin_886
10 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 09:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy