LinuxQuestions.org
Review your favorite Linux distribution.
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, 08: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, 11:11 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
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
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
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


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


All times are GMT -5. The time now is 12:58 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration