bash does not retain env when running script

Matthew Woehlke mw_triad@users.sourceforge.net
Tue Nov 14 19:52:00 GMT 2006


Arto Stimms wrote:
> I would like to run a bash script with a few changes in the environment. I would expect this to work:
> [snip]
> As a small example I have tried using these two minimal files
> 
> init.sh:
>     hello () { echo "hello world"; }
>     alias listdir=ls
> 
> script:
>     hello
>     listdir
> 
> I get the following output:
> 
>     $ bash --rcfile init.sh script
>     script: line 1: hello: command not found
>     script: line 2: listdir: command not found
> 
> What can I do to make my changes work in the script?

'script' is being run in a subshell, and you cannot export aliases to a 
subshell (but there are things you can do to get an rc file to run for a 
subshell; read 'man bash'). For the function, try 'export'ing it.

None of this has anything to do with Cygwin.

-- 
Matthew
Not to be used as a flotation device.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list