Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runing a function from Case Statement 3

Status
Not open for further replies.

chris01010

Programmer
Jan 29, 2004
25
GB
Hi,

I have the below script that should take the command line option and run the desired script on another server. Only it doesn't seem to run the function, infact it just returns back to the command line.

Code:
      case $1 in
           1) msgbacklog() ;;
           2) jobstatus() ;;
      esac

msgbacklog () 
{
ssh BLAH@SERVER1 > output 2>/dev/null  <<_EOF
/home/BLAH/backlog.ksh
_EOF
}

jobstatus () 
{
ssh BLAH@SERVER1 > output 2>/dev/null  <<_EOF
/home/BLAH/jobstatus.ksh
_EOF
}

Any ideas?
 
Hi

Two things :
[ol]
[li]You must define functions before calling them.[/li]
[li]You call functions without the parenthesis ( () ).[/li]
[/ol]


Feherke.
 
You must define functions before calling them
Really ?
In which sort of shell ?
 
Hi

PHV said:
Feherke said:
You must define functions before calling them
Really ?
In which sort of shell ?
Code:
[blue]master #[/blue] cat sh.sh 
case 1 in
1) foo ;;
esac

foo()
{
date
}

[blue]master #[/blue] bash sh.sh 
sh.sh: line 2: foo: command not found

[blue]master #[/blue] dash sh.sh 
sh.sh: 2: sh.sh: foo: not found

[blue]master #[/blue] mksh sh.sh 
sh.sh[3]: foo: not found

[blue]master #[/blue] zsh sh.sh 
sh.sh:2: command not found: foo
Vs.
Code:
[blue]master #[/blue] cat sh.sh 
foo()
{
date
}

case 1 in
1) foo ;;
esac

[blue]master #[/blue] dash sh.sh 
Tue Dec  6 17:20:14 EET 2011

[blue]master #[/blue] bash sh.sh 
Tue Dec  6 17:20:17 EET 2011

[blue]master #[/blue] mksh sh.sh 
Tue Dec  6 17:20:20 EET 2011

[blue]master #[/blue] zsh sh.sh 
Tue Dec  6 17:20:23 EET 2011
I would say, all Bourne shell compatible shells. Was my conclusion wrong ?

Feherke.
 
OOps, you're right.
Same beaviour with legacy bourne shell and korn shell.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The original answer, and the concise defense of said answer deserves a star!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top