My bash function definition are not sourced in /etc/profile.d because of error : as name contains unsupported characters ???
Feb 05 16:22:09 localhost.localdomain JCD_PROFILE.D_COMMON_FUNCTION[3311]: /etc/profile.d/zzzz1_system_common_function_full.sh - BEGIN - ID : uid=1002(user_test_step1_vb) gid=100(users) groups=100(users),464(vboxsf) - USER : user_test_step1_vb - HOME : /home/user_test_step1_vb - LOG_USER :
Feb 05 16:22:10 localhost.localdomain JCD_SYSTEM_COMMON_FUNC[3312]: zzzz1_system_common_function_full.sh - SYSTEM_COMMON_FUNCTION_EXPORT : 1
Feb 05 16:22:10 localhost.localdomain JCD_SYSTEM_COMMON_FUNC[3315]: /etc/profile.d/zzzz1_system_common_function_full.sh - ^^^ END ^^^ - USER : user_test_step1_vb
Feb 05 16:22:10 localhost.localdomain JCD_PROFILE.D_COMMON_GEN_ENV[3320]: /etc/profile.d/zzzz2_system_common_general_env_var - BEGIN - ID : uid=1002(user_test_step1_vb) gid=100(users) groups=100(users),464(vboxsf) - USER : user_test_step1_vb - HOME : /home/user_test_step1_vb - LOG_USER :
Feb 05 16:22:10 localhost.localdomain JCD_PROFILE.D_COMMON_GEN_ENV[3349]: zzzz2_system_common_general_env_var - SYSTEM_COMMON_GENERAL_ENV_VAR_EXPORT : 1
Feb 05 16:22:10 localhost.localdomain JCD_PROFILE.D_COMMON_GEN_ENV[3352]: /etc/profile.d/zzzz2_system_common_general_env_var - ^^^ END ^^^ - USER : user_test_step1_vb
Feb 05 16:22:10 localhost.localdomain startplasma-x11[3227]: org.kde.plasma.libkworkspace: Skipping syncing of environment variable "BASH_FUNC__MY_ECHO_%%" as name contains unsupported characters
Feb 05 16:22:10 localhost.localdomain startplasma-x11[3227]: org.kde.plasma.libkworkspace: Skipping syncing of environment variable "BASH_FUNC__MY_LS_%%" as name contains unsupported characters
Feb 05 16:22:10 localhost.localdomain startplasma-x11[3227]: org.kde.plasma.libkworkspace: Skipping syncing of environment variable "BASH_FUNC_abort_because_test%%" as name contains unsupported characters
Feb 05 16:22:10 localhost.localdomain startplasma-x11[3227]: org.kde.plasma.libkworkspace: Skipping syncing of environment variable "BASH_FUNC_abort_because_test_no_trap%%" as name contains unsupported characters
In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit.
#
# Source profile.d files and UTF8 settings
#
# But do not source this if PROFILEREAD is already set to avoid
# overriding locale variables already present in the environment
#
if test -z "$PROFILEREAD" ; then
test -r /etc/profile.d/sh.ssh && . /etc/profile.d/sh.ssh
fi
#
# Source profile extensions for certain packages, the super
# may disable some of them by setting the sticky bit.
#
if test -d /etc/profile.d -a -z "$PROFILEREAD" ; then
for s in /etc/profile.d/*.sh ; do
test -r $s -a ! -k $s && . $s
done
unset s
fi
That seems not relative to systemd it is just sourced bash script
I have made another test.
If I source my functions definition in user .profile (~/.profile) I got the same errors in journald, but in this case the functions are available for the logged user. That is not the case when sourcing from /etc/profile.d
I found comments on the internet that confirm the rejection of environmental variables by systemd if they contain errors.
In particular the use of ‘%’ seems unauthorized.
This is not my case, because I only use '[A-Za-z0-9] and [_].
So who can afford to replace
_MY_ECHO_
by _MY_ECHO_%%
J’ai aussi trouvé un commentaire de Mr Lennart Poettering
It exports a shell function to get this function defined in sub-shell. And when you export a function in bash you get such variable defined in the environment.
Well, but it does so much more than exporting it to the subshell: every process will inherit that, not just bash… Isn’t the clean approach here to make those subshells source these functions in themselves from somewhere, so that only bash gets it? i.e. propagating bash functions by env vars down the tree and into systemd --user sounds like a pretty poor way of doing these things to me…
Is there a better way to add functions to bash without rewrite bash iself?
A yes ! Don’t use bash.
Step 1: computer boot
Step 2 : normal user logged in
Step 3 : Verifying in journald that functions are not exported
Step 4 : Open a terminal and type :