Shell and echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell and echo
# 1  
Old 02-26-2008
Shell and echo

Probably my first post, very new to shell scripting Smilie

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  
Old 02-26-2008
Position the function

Place the function above the while loop. It must be available before you can reference it.
# 3  
Old 02-27-2008
Smilie Thankssssss
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem in exit in same shell with echo

Hello All, I am in SunOS usvh3eudv80 5.10. facing problem in my script: #!/bin/bash var1=`date +"%m%d%H%M"%S.zip` echo " Hi your current dir is :---> $(pwd)";echo " Changing to home dir:" cd ~ 2>/dev/null || {echo "Change dir failed ....Quiting...." && exit 2 }; ls -lrt echo... (3 Replies)
Discussion started by: krsnadasa
3 Replies

2. Shell Programming and Scripting

Shell Script if $2 is greater than 10 then echo $1

Hi, I have a file output.txt 3258 14 32647 10 32649 10 32650 10 32651 10 32652 10 32653 10 32654 10 32655 10 32656 10 32515 09 32478 08 32555 08 35888 08 (4 Replies)
Discussion started by: amit_spl
4 Replies

3. Shell Programming and Scripting

C Shell in linux.. only recognizes echo command

Hi guys, So my code is below. This is a simplified version of the shell... It does not continue for ever... I guess its actually rather a program to accept a command.. has the fork and the execve etc. Anyways when i compile it and run it in the terminal for some reason only '/bin/echo "enter... (1 Reply)
Discussion started by: 1bh
1 Replies

4. Shell Programming and Scripting

echo prints nothing-shell script

could anyone tell me why when i execute the following script, echo returns blank set k = 1 echo $k (9 Replies)
Discussion started by: saman_glorious
9 Replies

5. Shell Programming and Scripting

shell echo help needed

echo '#!/usr/local/bin/expect' > sree_expt echo "spawn passwd $User" >> sree_expt echo 'expect "New password:"' >> sree_expt echo send "$Password\r" >> sree_expt echo 'expect "Re-enter new password:"' >> sree_expt echo send "$Password\r" >> sree_expt echo "expect eof" >> sree_expt for... (0 Replies)
Discussion started by: sreedhargouda
0 Replies

6. Solaris

Confused with echo $SHELL Command....

Hi.. Everyone... Kindly consider following : login as: root Using keyboard-interactive authentication. Password: Last login: Mon Nov 3 19:30:50 2008 from xxxxxxxxxxx Sun Microsystems Inc. SunOS 5.10 Generic January 2005 You have new mail. Sourcing //.profile-EIS..... # # ... (3 Replies)
Discussion started by: Reboot
3 Replies

7. UNIX for Advanced & Expert Users

Echo with ksh shell

Hi All, I'm trying to use the "echo" command in a korn shell script, and I want it to drop the trailing newline. Now I know that with the bash shell, the "-n" flag would solve this issue. Does anyone know how this can be done with the korn shell? Cheers Khoom (10 Replies)
Discussion started by: Khoomfire
10 Replies

8. UNIX for Advanced & Expert Users

run a shell script with echo

I need to schedule a shell script that runs at the command prompt to run with crontab. When I run this at the command prompt as follows it works: echo /usr/test/script.sh date1 date2 y | at 20:00 But if I will pass these argument (date1, date2, Y) with in a shell script (say scr1.sh) and... (7 Replies)
Discussion started by: keerthi
7 Replies

9. Shell Programming and Scripting

Echo escaped \c in SH Shell Any Idea

Hi All, I have got an echo statement with "\c" in it to avoid getting into a newline. Ths script is using #!\bin\sh Any idea what could make it to escape "\c" (4 Replies)
Discussion started by: asami
4 Replies

10. UNIX for Dummies Questions & Answers

echo $SHELL, $PWD and etc.

hi, this echo $SHELL will give the shell name.. how to get the other list of variables (besides SHELL) values? and also, different shells have different variable names (example SHELL) (10 Replies)
Discussion started by: yls177
10 Replies
Login or Register to Ask a Question