ksh loop to read input until QUIT

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh loop to read input until QUIT
# 1  
Old 07-19-2017
ksh loop to read input until QUIT

I'm looking to write a simple ksh loop reading user input (and write it to a file) until the user enters QUIT at which point I want it to continue.
Does anyone have an example of this type of loop?
Any help much appreciated
# 2  
Old 07-19-2017
Hello Grueben,

Could you please try following and let me know if this helps you.
while true; do echo "Enter your choice:"; read var; if [[ "$var" == "quit" ]]; then break;fi; echo $var", I am printing this variable here, you could use it as per your need."; done

Execution and standard output will be as follows.
Enter your choice:
chumma, I am printing this variable here, you could use it as per your need.
Enter your choice:
singh, I am printing this variable here, you could use it as per your need.
Enter your choice:

R. Singh
# 3  
Old 07-19-2017
To save 5 keystrokes typing QUIT, how about this dual key single keystroke:-
echo "Press Ctrl-D to QUIT and continue..."
cat > /dev/null # /full/path/to/filename
echo "You are here..."

Results using OSX 10.12.5, default bash terminal calling ksh.
Last login: Wed Jul 19 18:55:07 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./input_txt.sh
Press Ctrl-D to QUIT and continue...
You are here...
AMIGA:barrywalker~/Desktop/Code/Shell> exit
Saving session...
...copying shared history...
...saving history...truncating history files...

[Process completed]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh - Read input from file and output CSV i same row

Hello I have the following output and want the output to look: FROM: GigabitEthernet0/0 is up, line protocol is up 1 input errors, 0 CRC, 0 frame, 1 overrun, 0 ignored 275 output errors, 0 collisions, 3 interface resets GigabitEthernet0/1 is up, line protocol is up 0... (4 Replies)
Discussion started by: JayJay2018
4 Replies

2. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

3. Shell Programming and Scripting

ksh to read input until QUI

Hello all I'm looking to write a simple script (ksh/sh/bsh) to read user input and write it to a file (adding each time) until the user enters QUIT at which point I'm hoping to ask some more questions. Any help much apprecited (2 Replies)
Discussion started by: Grueben
2 Replies

4. Shell Programming and Scripting

ksh while read loop breaks after one record - AIX

#!/bin/ksh for SRV in imawasp01 \ imawasp02 \ imawasp03 \ imawasp04 \ imawasp05 \ imawasp06 \ imawasp07 \ imawasp08 \ imawasp09 do print "${SRV}" while read PASSLINE do SRVNAME=`echo ${PASSLINE} | awk -F\: '{print $1}'` LASTLOGIN=`ssh ${SRV} lsuser ${SRVNAME} | tr '... (2 Replies)
Discussion started by: port43
2 Replies

5. Shell Programming and Scripting

Read multiple input from CLI :ksh

Hi folks.. i got a requirement to red multiple directories from STDIN and store them to a variable. ex:- echo "Enter directory to add:" echo " Enter directory to add:" read value till there is input and when there is no input close the read loop and store variable into an array ... (1 Reply)
Discussion started by: bangaram
1 Replies

6. Shell Programming and Scripting

[KSH] Creating automatic variable from read input

Hello there, I am posting to seek help with a KSH script, I am making a simple calculation program where the user can enter as many numbers as they like, I am getting their input using the read command, however I am not sure how to repeat doing this and storing the input in to new variables... (7 Replies)
Discussion started by: pandapowerbox
7 Replies

7. Shell Programming and Scripting

perl how to exit a while loop and quit reading the input file

I am reading a file using While loop while <FILE> { $_ = <FILE>; process data... } I would like to quit reading the file once I encounter a String pattern. How do i do it. is it if (/SUMMARY/) { last; } I am having problems with uninitialized value in pattern... (1 Reply)
Discussion started by: subhap
1 Replies

8. Shell Programming and Scripting

read command (input) inside the while loop

Hi, 'read' command is not working inside the while loop, How can I solve this? Rgds, Sharif. (2 Replies)
Discussion started by: sharif
2 Replies

9. UNIX for Dummies Questions & Answers

read user input from within a wile loop that is being fed from below

hi! i need to do a ksh script that uses a wile loop that is fed form below while read line do some things done < myfile inside the while loop i need to read user input to ask the user what he wants to do, but "read" reads the file, and not the standard input while read line do ... (2 Replies)
Discussion started by: broli
2 Replies

10. Shell Programming and Scripting

input inside while read loop

Hi all Does anyone have a script that will allow me to stop inside a while read loop. I want to pause the loop until a enter is pressed. e.g. While read line do echo something if LINECOUNT > 40 then read ENTER?"PRESS ENTER TO CONT..." ... (3 Replies)
Discussion started by: jhansrod
3 Replies
Login or Register to Ask a Question

Featured Tech Videos