Function visibility

2007-10-01 Thread retiredff

I have several functions in my /etc/profile (Mac OSX 10.4.9). I can use the
functions at the commandline, however inside of scripts I receive an error.
I'll use an example of a function I have called cecho that echo's a string
in a color that is passed in $2, $1 has the string: 

./maintenance: line 27: cecho: command not found

If I run this from the command line, it works fine. What am I doing wrong? 
I also have the same problem with any alias commands I use inside of
scripts. If I type 'set' on the CLI it lists all of the functions. Should I
use export function-name?

TIA

TonyB

-- 
View this message in context: 
http://www.nabble.com/Function-visibility-tf4551985.html#a12990189
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: Function visibility

2007-10-01 Thread retiredff



On Monday 01 October 2007, retiredff wrote:
> I have several functions in my /etc/profile (Mac OSX 10.4.9). I can use
> the
> functions at the commandline, however inside of scripts I receive an
> error.
> I'll use an example of a function I have called cecho that echo's a string
> in a color that is passed in $2, $1 has the string:
>
> ./maintenance: line 27: cecho: command not found
>
> If I run this from the command line, it works fine. What am I doing wrong?
> I also have the same problem with any alias commands I use inside of
> scripts. If I type 'set' on the CLI it lists all of the functions.

scripts are not interactive shells so you wouldnt have the same environment
as 
an interactive shell ... so you need to place the definitions of functions 
into a file and have the script source that at start

> Should I use export function-name?

that would only help when you executed the script from a shell which sourced 
the /etc/profile and not if it were run through say a cronjob
-mike

 
Thanks mike. It's been awhile since I programmed in Bash. I remember
now..



-- 
View this message in context: 
http://www.nabble.com/Function-visibility-tf4551985.html#a12990931
Sent from the Gnu - Bash mailing list archive at Nabble.com.