LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2012, 09:30 AM   #1
rit
LQ Newbie
 
Registered: Feb 2012
Location: kanpur,india
Posts: 21

Rep: Reputation: Disabled
problem in case statement


hello everyone,

Code:
while :
 do
    clear
    echo "-------------------------------------"
    echo " Main Menu "
    echo "-------------------------------------"
    echo "[1] Show Todays date/time"
    echo "[2] Show files in current directory"
    echo "[3] Show calendar"
    echo "[4] Start editor to write letters"
    echo "[5] Exit/Stop"
    echo "======================="
    echo -n "Enter your menu choice [1-5]: "
    read yourch
    case $yourch in
      1) echo "Today is `date` , press a key. . ." ; read ;;
      2) echo "Files in `pwd`" ; ls -l ; echo "Press a key. . ." ;   read ;;
      3) cal ; echo "Press a key. . ." ; read ;;
      4) vi ;;
      5) exit 0 ;;
      *) echo "Opps!!! Please select choice 1,2,3,4, or 5";
         echo "Press a key. . ." ; read ;;
 esac
done
when i remove read command from case 1,2,3 it is not displaying the echo content in all first 3 cases but it is working if read command is not removed.
please tell me why this is happening
and why -n is used with echo
 
Old 03-25-2012, 09:39 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Because without the reads, the loop iterates and the clear is executed. Remove the clear and see how it looks.

echo's -n option stops it appending a newline to whatever it echos. In this case it leaves the cursor after your prompt string (which looks right), otherwise the cursor would be on the next line in column one.
 
1 members found this post helpful.
Old 03-25-2012, 11:01 AM   #3
rit
LQ Newbie
 
Registered: Feb 2012
Location: kanpur,india
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
Because without the reads, the loop iterates and the clear is executed. Remove the clear and see how it looks.

echo's -n option stops it appending a newline to whatever it echos. In this case it leaves the cursor after your prompt string (which looks right), otherwise the cursor would be on the next line in column one.
thankyou for your help
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with case statement in shell script ayamkudy Programming 2 05-24-2011 02:18 PM
Perl switch statement throwing error like Bad case statement (invalid case value?) kavil Programming 2 10-07-2010 04:50 AM
Case Statement craigjward Programming 6 12-12-2007 11:33 PM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM
case statement baks Programming 2 03-15-2007 01:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration