Enter q for quit not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Enter q for quit not working
# 1  
Old 08-27-2010
Question Enter q for quit not working

I'm using a while loop with an if statement. When the user choses a number, it will display a list of files. That works, the problem is q for quit won't exit script. How can I fix this?
# 2  
Old 08-27-2010
Hi.

Code:
break

will ordinarily end an iterative cycle. Without more details (i.e. seeing your script), I can't be more specific than that!
# 3  
Old 08-27-2010
Network Code for enter q to quit

Code:
echo "Enter week number or q to quit: "
read num
while $num != q
do
       if [ $num -lt 4 ]
          then
             echo "The files submitted in week $num are"
                   ls ../week$num
           else
              echo "Incorrect week number!"
      fi
      echo "Enter week number or q to quit: "
      read num
done

the loop has to continue until user tells it to quit, but I can't get the program to take the q. It just keeps going with the script.

Last edited by Scott; 08-28-2010 at 05:58 AM.. Reason: Please use code tags
# 4  
Old 08-27-2010
After fixing the bad test on the while statement, it worked for me in both bash and kshell.

Code:
#!/usr/bin/env ksh
echo "Enter week number or q to quit: "
read num
set -x                      # add this line to help debug the loop
while  [[ $num != q ]]
do
        if  [[ $num < 4 ]]
        then
                echo "The files submitted in week $num are"
                ls ../week$num
        else
                echo "Incorrect week number!"     
        fi
        echo "Enter week number or q to quit: "
        read num
done

This User Gave Thanks to agama For This Post:
# 5  
Old 08-28-2010
Power Help

Not sure why it won't work, but I tried agama's suggestion and it still won't work. Any other suggestions.
# 6  
Old 08-28-2010
Since the code works for me in my environment, the only way I might suggest something is if you execute the script with the set -x in place and posting the ouput when you run the script.
# 7  
Old 08-28-2010
try Smilie

Code:
#!/bin/bash
read -p "Enter week number or q to quit: " num
 while [ $num != "q" ] ;
do
       if [ $num -lt 4 ]
          then
             echo "The files submitted in week $num are"
                   ls ../week$num
           else
              echo "Incorrect week number!"
      fi
      read -p "Enter week number or q to quit: " num
done

This User Gave Thanks to ygemici For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. OS X (Apple)

Are you sure you want to quit Safari?

Hmmm. I cannot figure out where to disable this warning message in Safari. Google says to disable something in Safari Tabs preferences but my Macs do not have that option in Mojave. Anyone know how to disable the following so when I quit Safari it simply quits without the "freeze the... (12 Replies)
Discussion started by: Neo
12 Replies

2. Shell Programming and Scripting

Need to quit out of for loop.

Hi, Here is my code to send read.txt to three servers. col="prd167.mybank.com prd168.mybank.com bsprd169.mybank.com" set -A look $col for IndixList in ${look}; do scp /tmp/read.txt admin@$IndixList:/tmp done This works and all the 3 servers gets the read.txt file. However,... (8 Replies)
Discussion started by: mohtashims
8 Replies

3. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

4. Shell Programming and Scripting

if no file then quit

I have a script that run several subscripts. I need to find out how to do two things. First I would like to check for a file and if that file is not there I want to quit the entire script without running the rest of the script which contain subscripts. If the file is there, I want it to continue... (1 Reply)
Discussion started by: libertyforall
1 Replies

5. Shell Programming and Scripting

How to quit from a script?

hi all, I am facing problem in shell scripting while using exit command, when ever i run a file using . ./<filename>, when i run the sae script as sh <filename> the script does not close the windows. since my script has function calls i have to use . ./ <filename>. Could any one tell me... (8 Replies)
Discussion started by: caro
8 Replies

6. Shell Programming and Scripting

"Write" - how to quit by press enter

I need to make Bash script. It has one parameter - user ID. If this user is online you can write him a message with "write" program, but only one line. After pressing ENTER "write" program should quit. Normally when you run "write" you can write next line after pressing ENTER and you can quit... (0 Replies)
Discussion started by: Eriknem
0 Replies

7. Shell Programming and Scripting

quit any time

how can i read input to quit any time, for instance "type q to quit" I have a script like this echo "The first choice" read firstChoice echo "The second choice" read secondChoice Looking for a code to quit any time by pressing q to quit any help would be appreciated thanks (5 Replies)
Discussion started by: Qwond
5 Replies

8. UNIX for Dummies Questions & Answers

how to quit from glance

hi, if i am in glance, how do i exit? thanks (2 Replies)
Discussion started by: yls177
2 Replies
Login or Register to Ask a Question