Jump to content

bash and functions [Solved]


Recommended Posts

OK, I'm trying to write a bash script - so I googled a couple of tutorials and got started. The first thing I wanted to do was to write a simpel function - all the tutorials seemed to suggest I could.

 

So, to test the concept I wrote the following:

 

#!/bin/bash
echo "Thanks for coming..."
finish

function finish() {
 echo "done..."
 EOF
}

 

When I attempt to run this I get:

 

Thanks for coming...
./myuwefit.sh: line 8: finish: command not found

 

So, what am I missing here...?

Link to comment
Share on other sites

It seems that

The function definition must precede the first call to it. There is no method of "declaring" the function, as, for example, in C.
(from the advanced bash guide).

 

So it checks it line by line, and when you call it, it doesn't know what it is. If you define it and then call it, then it knows what to do. ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...