Enter q for quit not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Enter q for quit not working
# 8  
Old 08-28-2010
Hammer & Screwdriver Next part

Now it must ask the user for a file from list of week submissions. Do I put the next while loop within the original loop or after it? Here's the loop:
Code:
while [ $file != "q" ];
do
      if [ -f ../week$num/&file ]
          then 
             echo "The contents of the $file are: "
                 cat ../week$num/$file
                    break
              else
                 read -p "Incorrect file name! Please select again or enter q: " file
      fi
done


Last edited by Scott; 08-28-2010 at 06:32 PM.. Reason: Code tags, please...
# 9  
Old 08-28-2010
try this Smilie

Code:
#!/bin/bash
read -p "Enter week number or q to quit: " num
 while [ $num != "q" ] ;
   do
    if [ $num -lt 4 ] ; then
     echo -e "The files submitted in week $num are\n" `ls -1 ../week$num| grep -v to`
    else
     echo "Incorrect week number!..exiting"
     break
    fi
     echo ""
     read -p "Do you want to view contens for file..(y/n)  " choice
    if [ $choice == "y" ] ; then
     echo -e  "the files \n====Files in week$num dir====\n`ls -1 ../week$num|grep -v to`"
      read -p "Enter name for view file or q to quit: " file
       if [ -f "../week$num/$file" ] ; then
         echo "The contents of the $file are: " `cat ../week$num/$file`
       else
         read -p "Incorrect file name! Please select again or enter q: " file
         break
       fi
    fi
      read -p "Enter week number or q to quit: " num
   done

# 10  
Old 08-28-2010
Bug Like idea

While I like your idea, the program has to list the files so the user can choose one to view. That's why I figured using nested while loops would work.
# 11  
Old 08-28-2010
Quote:
Originally Posted by smiley76112
While I like your idea, the program has to list the files so the user can choose one to view. That's why I figured using nested while loops would work.
i want to use a few loops in script for fast and intelligibility..
you can expand a one nested while loop for more condition..
if you want to more help i can Smilie

good practices Smilie
 
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