Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I run it with debug sh -x ./tester.sh and I get a totally different output:
Quote:
+ function Output
tester.sh: 1: function: not found
+ echo hello World
hello World
+ Output
tester.sh: 1: Output: not found
Why is it complaining about the function command??
Am I seriously doing something fundamentally wrong here? Shall I consult a doctor because my IQ has now dropped to equal a squashed watermelon?
The script works perfectly. But when I check "under the hood" in the debug mode it is complaining. I have never come across that before so am wondering whats going on.
I have tried it on 2 other machines and still the same error. So cant be me... can it?
Shells that don't like this kind of function declaration are Ash, Bsh, Csh and Jsh (as in checking for odd shell linkage which clearly didn't happen anyway). However the exact"tester.sh: 1: function: not found" error I can only reproduce using /bin/bash when 0) invoked as 'sh' AND 1) removing the "function" from the "function Output" line. (The other shells will spit out other types of errors.) Which is odd as with current Bash-2 you wouldn't even need to explicitly use the "function" tag to declare a function as "name() { doSomething; }" will do easily...
//BTW with my systems I didn't see no errors either. I wonder though what doctor could help the OP ;-p
Last edited by unSpawn; 10-17-2009 at 08:47 AM.
Reason: //More *is* more...
I can't test it right now to duplicate the error I think it's complaining because the function doesn't have anything to do. It looks at the Output line at the bottom for something to plug into the function and doesn't find anything. Try:
function Output
{
echo $1 $2
}
Output Hello World
Output Good Bye
Output One Two
A function performs the action between the brackets on every line you have listed below it with the variables ($1 $2 here) being substituted in the function. So this runs echo $1 $2 on the line "Hello World" then runs echo again on "Good Bye" then runs it again on "One Two" etc.
Interesting, about using dash for /bin/sh. At least the results can be explained now. To tell you the truth it is the first time I've heard of it. There is a wikipedia article on it. Looks like Debian and Ubuntu have this as their default for /bin/sh.
Well nevermind, I should have read the thread more carefully and tested the original function first. I ran it and it doesn't give any error here either.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.