Register
It is currently Thu Apr 24, 2014 12:16 am

Calling a function


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Jun 12, 2011 2:28 am   
User avatar

Joined: Sat Dec 11, 2010 5:27 pm
Posts: 13
Location: NSW, Australia
I have a function - dircheck - which is in the file .bash_functions which is read within .bashrc.

The function works OK if I type its name in the terminal screen. It does not work if I call the function from within a bash script -
Code:
#!/bin/bash
echo Test
dircheck
if dircheck
    then echo OK
    else echo Wrong
fi

I get the message
Quote:
Test
/home/user/bin/Test: line 5: dircheck: command not found
/home/user/bin/Test: line 7: dircheck: command not found
Wrong

All permissions and paths have been checked and are OK.

Help please. TIA

Alan


Top
 Profile  
 PostPosted: Sun Jun 12, 2011 7:11 am   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
You have to export your function. ( « help export » )

So, your .bash_functions should look like that :

Code:
dircheck() [[ -d "$1" ]]
export -f dircheck


Or alternatively, you can export the function directly from your .bashrc (because you've just sourced it) :

Code:
. $HOME/.bash_functions
export -f dircheck


Top
 Profile  
 PostPosted: Sun Jun 12, 2011 9:14 pm   
User avatar

Joined: Sat Dec 11, 2010 5:27 pm
Posts: 13
Location: NSW, Australia
That fixed the problem - thanks for your help

Alan


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP