LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-31-2008, 12:55 AM   #1
viveksnv
Member
 
Registered: Feb 2008
Posts: 38

Rep: Reputation: 15
functions in case conditions


Bash Scripting
Hello all,
how to invoke functions in case conditions.


function first
{
---
}
case
0)first;;
1)----
esac


But this does not work.

help me.
 
Old 03-31-2008, 06:00 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
"Doesn't work" is way too inaccurate to describe that a script is not working as expected.

Run your script using
Code:
sh -x myscript
and try to find out what actually happens. If it is really not understandable, feel free to ask again.

jlinkels
 
Old 04-02-2008, 03:28 PM   #3
prad77
Member
 
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
what err msgs you are getting?
throw enough debug echos to track your code if possible.

Gentoo

Last edited by prad77; 04-17-2008 at 03:38 AM.
 
Old 04-02-2008, 03:36 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
works for me

Code:
$ cat t.sh
#!/bin/ksh

first () {
        echo "this is the fucntion 'first', arguments: $@"
}

v=0

case $v in
0)
        first some args
        ;;
*)
        echo "not running first"
        ;;
esac

$ ./t.sh
this is the fucntion 'first', arguments: some args
 
Old 04-02-2008, 10:15 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
My very-frank suggestion to you is ... bash-scripting is highly over-rated!

I mean... let's get serious here. You're working in an environment that probably has at least three very-good full fledged programming-environments pre-installed and ready to go: Perl, Python, and PHP. Maybe even Ruby.

Any of those systems can be used to run your program, by the trivially-simple expedient of "shebang" ... #!command_name ... and the person (or the program) who's running your program will therefore neither know nor care.

In other words ... "if you're monkeying-around too much with bash-scripting, you're missing the point."

You have "a preponderance of riches." Deal with it.

"Bash" is intended to be ... a shell. Nothing more, nothing less. As such, it has a modicum of simple scripting-capabilities, mostly to let you specify slightly-complex things if-and-when you want to. But did "Bash" ever set out to be a programming language? No... why should it?

Bash is a shell...

Perl|PHP|Python|Ruby is a language.

... And you have equal and unlimited access to all of them.

Plan accordingly.
 
  


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
renaming directories from upper case to lower case, help!! linux_teller Linux - Newbie 3 03-07-2008 05:15 AM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 12:01 PM
string functions in C to make word case independant? knobby67 Programming 1 03-19-2007 01:13 PM
mesa-6.x claims to support OpenGL 1.5, but in my case does not in my case. qwijibow Programming 2 11-23-2006 07:14 AM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:37 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