LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2009, 07:43 PM   #1
methodtwo
Member
 
Registered: May 2007
Posts: 146

Rep: Reputation: 18
bash scripting question


'm learning bash but i don't understand how to call functions that are defined later.For example:

Code:
cmdz
function cmdz{
local cmd args
while read -e -p "> " cmd args; do
        case $cmd in
                sa ) select_all args ;;
                rd ) read_date args ;;
                ra ) read_attendee args ;;
                sd ) sorted_data args ;;
                q  ) exit
        esac
done
}
When i run this simple bit of code i just get an error saying that the "command" cmdz not found.So what is wrong here?
Any help would be great.Thankx in advance
 
Old 02-15-2009, 10:11 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
I recommend you take a look at the Advanced Bash-Scripting Guide where you will read, "The function definition must precede the first call to it. There is no method of "declaring" the function, as, for example, in C."
 
Old 02-16-2009, 12:13 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Note that if you define a function A that calls function B, it is possible to define A before B if B is defined before the first call to A.
 
  


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
bash scripting question Locura Linux - General 5 09-02-2006 09:13 AM
Bash scripting question ajaye1971 Linux - Newbie 1 11-16-2005 07:29 PM
BASH Scripting question rootking Linux - Software 14 12-15-2004 12:16 PM
bash scripting question brian0918 Linux - Newbie 7 06-26-2003 03:48 PM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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