You could also use bash
's exported function feature. However, given that fakeroot
is an sh
script, you'd need to be on a system where the sh
implementation doesn't strip those BASH_FUNC_fname%%
variables from the environment like dash
does. To make sure it doesn't happen you could have fakeroot
interpreted by bash
itself as bash -o posix
which is a sh
interpreter.
#!/bin/bash -
myVar="foo"
testFunction() {
printf '%s\n' "$myVar"
}
export myVar
export -f testFunction
fakeroot=$(command -v fakeroot)
bash -o posix -- "${fakeroot:?fakeroot not found}" -- bash -c testFunction
Note that you also need to export myVar
for that to be available to the bash
started by fakeroot
. Instead of calling export
for both myVar
and testFunction
, you could also issue a set -o allexport
before declaring them.
fakeroot
isn't causing this. You could removefakeroot
and you'd get the problem simply withbash -c testFunction
. So it probably falls into xyproblem.info category. You're trying to solve with Y, what's the actual X? Anyway, you can run your whole script with fakeroot outside of it to solve this (and also remove bash -c of course)makepkg
do it?