Skip to main content
edited tags
Link
muru
  • 78.4k
  • 16
  • 214
  • 320
added 290 characters in body
Source Link
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

I have a bash function declared like so:

function foo {
  echo "this is foo";
}

I didn't call export -f foo, but it still was available in subshells.

However, typically when I declare a function like this instead:

foo(){
  echo "this is foo";
}

then I have to call:

export -f foo;

am I imagining things, are is there a difference in export behavior in the different declaration syntax?

Note that I didn't need to export the functions as far as I can tell when I just did:

. my_script_with_foo_in_it.sh  # this is in ~/.bash_profile/.bashrc

then later in a bash shell I could call:

foo

without any issue, even without exporting the function.

I have a bash function declared like so:

function foo {
  echo "this is foo";
}

I didn't call export -f foo, but it still was available in subshells.

However, typically when I declare a function like this instead:

foo(){
  echo "this is foo";
}

then I have to call:

export -f foo;

am I imagining things, are is there a difference in export behavior in the different declaration syntax?

I have a bash function declared like so:

function foo {
  echo "this is foo";
}

I didn't call export -f foo, but it still was available in subshells.

However, typically when I declare a function like this instead:

foo(){
  echo "this is foo";
}

then I have to call:

export -f foo;

am I imagining things, are is there a difference in export behavior in the different declaration syntax?

Note that I didn't need to export the functions as far as I can tell when I just did:

. my_script_with_foo_in_it.sh  # this is in ~/.bash_profile/.bashrc

then later in a bash shell I could call:

foo

without any issue, even without exporting the function.

added 2 characters in body
Source Link
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

I have a bash function declared like so:

function foo {
  echo "this is foo";
}

I didn't call export -f fooexport -f foo, but it still was available in subshells.

However, typically when I declare a function like this instead:

foo(){
  echo "this is foo";
}

then I have to call:

export -f foo;

am I imagining things, are is there a difference in export behavior in the different declaration syntax?

I have a bash function declared like so:

function foo {
  echo "this is foo";
}

I didn't call export -f foo, but it still was available in subshells.

However, typically when I declare a function like this instead:

foo(){
  echo "this is foo";
}

then I have to call:

export -f foo;

am I imagining things, are is there a difference in export behavior in the different declaration syntax?

I have a bash function declared like so:

function foo {
  echo "this is foo";
}

I didn't call export -f foo, but it still was available in subshells.

However, typically when I declare a function like this instead:

foo(){
  echo "this is foo";
}

then I have to call:

export -f foo;

am I imagining things, are is there a difference in export behavior in the different declaration syntax?

Source Link
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214
Loading