The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Echo with ksh shell Khoomfire UNIX for Advanced & Expert Users 10 01-17-2008 10:04 AM
run a shell script with echo keerthi UNIX for Advanced & Expert Users 7 06-21-2006 05:38 PM
FTP--How to use echo?? rahul26 UNIX for Advanced & Expert Users 1 06-14-2006 09:47 AM
Echo escaped \c in SH Shell Any Idea asami Shell Programming and Scripting 4 05-04-2006 07:24 AM
echo $SHELL, $PWD and etc. yls177 UNIX for Dummies Questions & Answers 10 12-30-2002 10:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-26-2008
replyramdas replyramdas is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 2
Shell and echo

Probably my first post, very new to shell scripting

Here is the script i am trying to modify to use function

Code:
# Script to create simple menus and take action according to that selected
# menu item
#
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` "; echo "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
####################
i wan tto replace < echo "press a key. . ." ; read ;;> with a function as it is repeating five times. so i wrote a function like below and called at the right place as shown below, but it didnt worked, any reason ?

Code:
.
.
.
    read yourch
    case $yourch in
      1) echo "Today is `date` "; _mesg;;
      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

_mesg(){
	echo "press a key. . ." ; read ;
}
  #2 (permalink)  
Old 02-26-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Position the function

Place the function above the while loop. It must be available before you can reference it.
  #3 (permalink)  
Old 02-27-2008
replyramdas replyramdas is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 2
Thankssssss
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0