Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Solaris / sh

I have a few functions defined in a file which gets loaded via

. ./some_file.sh 

When I start a subshell with


All my function definitions are lost but when I do


I do see the source, is there an easy way to get them functional in my subshell?

share|improve this question

Functions are naturally propagated to subshells:

greet () {
  echo "hello, $1"
( echo "this is a subshell"; greet bob )

But they are not and cannot be propagated to independent shell processes that you start by invoking the shell under its name.

Bash has an extension to pass functions through the environment, but there's no such thing in other shells. While you can emulate the feature, it requires running code in the nested shell anyway. You might as well source your function definitions in the nested shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.