Function exported from ~/.profile not inherited
I defined and exported a bash function in ~/.profile. I'm calling it from the Exec command in a desktop file, something like bash -c f
where f is the exported function.
This is weird:
- It works when launching the desktop app from the dock.
- It works when launching the desktop app from xdg-open.
- It doesn't work when opening some file from nautilus using the desktop app.
I have checked dumps of the environment and shell options for every scenario above. The options are always the same, no privileged, no posix, nothing wrong there. The environment for 1 and 2 includes f, the one for 3 doesn't.
Now, the rest of the environment (simply variables, no other function) is ok, it's clear that the script launched by nautilus is inheriting it. Only the function is missing.
bash should be able to read any exported function in the environment. The documentation is not explicit about this (it only mentions subshells) but it's obvious from the fact that gnome shell, xdg-open, python -c "import os; os.system('bash -c set')", etc. are all able to see the exported function that, no matter whether the subshell is direct or mediated by non-shell processes, the environment is there to be read by bash.
So it seems as if nautilus is manipulating the environment somehow, maybe because of security or compatibility reasons.
I became obsessed about this issue, I would like to understand what is happening here.