If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > functions in common file?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-03-03, 08:41
niklasd niklasd is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
functions in common file?

Hi!

I'm trying to learn shell scripting and have runned into problems with functions.

Since you have to read all functions into memory before they are used it would be nice to be able to place all your functions in an functions.sh file and start the main script by running the function.sh script i.e. read all functions into memory.

Is this possible?

I have tried to place the functions in a script:

#!/bin/sh -vx

s_echo_hello()
{
echo hello
}


And then read it and tried to run the s_echo_hej in another script:

#!/bin/sh -vx

/tmp/common.sh

s_echo_hello


Here are the result:

#!/bin/sh -vx

/tmp/common.sh
+ /tmp/common.sh
#!/bin/sh -vx

s_echo_hej()
{
echo hej
}

s_echo_hej
+ s_echo_hej
./testi.sh: s_echo_hej: not found


Is this possible? And in that case, what am I doing wrong?


TIA

Niklas
Reply With Quote
  #2 (permalink)  
Old 10-03-03, 08:59
niklasd niklasd is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
Hi again!

I just figured it out from http://steve-parker.org/sh/functions.shtml#libraries

You have to put a . before you execute the script with your functions.

I have at this time no clue what that . means. Any one?

/Niklas
Reply With Quote
  #3 (permalink)  
Old 10-03-03, 09:36
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Quote:
Originally posted by niklasd
Hi again!

I just figured it out from http://steve-parker.org/sh/functions.shtml#libraries

You have to put a . before you execute the script with your functions.

I have at this time no clue what that . means. Any one?

/Niklas
It means 'source' the script into the current shell (as opposed to 'execute'). In some older shells you might actually have to use the word 'source' rather than the '.'.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On