Call function inside CASE


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Call function inside CASE
# 1  
Old 02-23-2012
Call function inside CASE

i have a case statement which branches to different sections based on an input. Each branch needs to call a function. below is the code. FOr some reason, the code inside the function is not getting executed. the code is below for reference.

in the below code echo "Function 1" which is there inside the function does not get executed. please let me know the fix for the same. thanks

Code:
#!/bin/ksh
function fn_1
{
echo "Function 1"
}
function fn_2
{
echo "Function 2"
}
ARG=DQ
case $ARG in
                DQ)
   fn_1()
                ;;
         MP)
   fn_2()
                ;;
                *)
  echo "Others"
                ;;
esac


Last edited by methyl; 02-23-2012 at 11:18 AM.. Reason: please use code tags
# 2  
Old 02-23-2012
Quote:
fn_1()
fn_2()
Lose the trailing brackets when calling the function. Should be:
Code:
 fn_1
 fn_2

# 3  
Old 02-23-2012
It doesn't get executed because it's going into the DQ section, not the MP one. Cases end at ;;

You call a function like functionname, not functionname(), incidentally.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. UNIX for Beginners Questions & Answers

Case inside While read File

Hi Experts, Need your guidance for case statement. I tried many way but no success yet.Now my existing code is doing something like below. Each Line of the input file contains one test case.#!/bin/bash FILE=$1 while read LINE; do do COMMAND done < $FILE Now I want to modify the code... (6 Replies)
Discussion started by: pradyumnajpn10
6 Replies

3. UNIX for Beginners Questions & Answers

How to call variable inside a function globally?

Hi Gurus, Is there a way to call a variable inside a function anywhere within the script? Thanks. BR, Ernesto (2 Replies)
Discussion started by: ernesto
2 Replies

4. Shell Programming and Scripting

Help on case to call recursively in UNIX Shell Script

Hi, I am New to Unix Shell Scripting basically, i need some help in achieving a case statement in Shell script to call recursively That is if case having like 1 2 3 4 options , if user inputs 1 and gets executed case should ask for options again but user should not input the same input value 1,... (7 Replies)
Discussion started by: karthikram
7 Replies

5. Shell Programming and Scripting

Nested case inside awk

please let me know if the below code could be written efficiently inside single awk case "$INP" in ksh) cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}' ;; pset) cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}' ;; dml) cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

6. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

7. Shell Programming and Scripting

Case inside case?

Im new to unix and shell scripting. I am required to write a program and im in the process of creating a menu system. I have my main menu but i want to be able to select an option that takes me onto another menu. I have tried doing this with the case statement with no luck so far. Wondering if it... (3 Replies)
Discussion started by: RAFC_99
3 Replies

8. Programming

how to call c executable inside c program??

hi guys i have only basic knowledge of c so guys plz help me ..... i want 2 call c executable which requires file name as argument and i need to modify file contents before calling that executable now my question is how can i call this c executable inside another c program with arguments ?? i... (9 Replies)
Discussion started by: zedex
9 Replies

9. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies
Login or Register to Ask a Question