Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-15-2009, 08:43 PM   #1
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:

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
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, 11:11 PM   #2
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, 01:13 AM   #3
Senior Member
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:13 AM
Bash scripting question ajaye1971 Linux - Newbie 1 11-16-2005 08:29 PM
BASH Scripting question rootking Linux - Software 14 12-15-2004 01:16 PM
bash scripting question brian0918 Linux - Newbie 7 06-26-2003 04:48 PM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 10:06 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration