LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   executed konsole from script does not "inherit" functions (https://www.linuxquestions.org/questions/linux-newbie-8/executed-konsole-from-script-does-not-inherit-functions-925496/)

sharky 01-24-2012 01:12 PM

executed konsole from script does not "inherit" functions
 
Example

Code:

#!/bin/bash

export VAR1=dummyvar1
export VAR2=dummyvar2

VAR_FUNC ()
{
export VAR3=dummyvar3
}

konsole -T "test_function"

In the konsole that is started from the script.


Quote:

> env | grep VAR
VAR1=dummyvar1
VAR2=dummyvar2
> VAR_FUNC
bash: VAR_FUNC: command not found
If I source the script then the function is found within the terminal where I sourced the script but the konsole that is started from the script doesn't have the function defined.

Am I doing something wrong?

David the H. 01-25-2012 09:13 AM

No, functions aren't something made available to subprocesses by default.

But bash does allow you to manually export them with the declare or export builtins.

Code:

export -f VAR_FUNC
sourcing is probably a better option overall though.

sharky 01-25-2012 12:03 PM

Quote:

Originally Posted by David the H. (Post 4584097)
No, functions aren't something made available to subprocesses by default.

But bash does allow you to manually export them with the declare or export builtins.

Code:

export -f VAR_FUNC
sourcing is probably a better option overall though.

That does it. thx.


All times are GMT -5. The time now is 07:50 PM.