Make it as the executable file: sudo chmod +x /etc/profile.d/keep-xdg.sh
KDE autostart adds this script. (Optional)
Reboot or logout then login
Check if the env variable exists: printenv | grep DO_NOT_OVERRIDE_XDG_CURRENT_DESKTOP
but it does not exist. ----> That is the issue.
~/.bashrc for bash or ~/.zshrc for zsh works fine with export env variable, but it is for individual user.
I want export env variable for all users, not individual user.
Do you have idea for solution?
How to set permanent global environment variables for all users?
Remove the hashbang line, i.e. #!/bin/sh. If you leave it in, then whatever code is in the file will be run in a subshell, and you cannot export a variable from a subshell to its own parent. You can only export variables and functions from the current environment into subshells thereof.
P.S.: None of the files in /etc/profile.d need to have the execute bit (+x) set for anyone, because they are sourced into the running environment, not executed.
No they dont.
This is true for things like /etc/environment and /etc/profile
But not true for their HOME counterparts such as ~/.profile
The way to get ‘other users’ env vars is probably not through some single administrative command, but your regular env initiated as the given user, ie:
I know that, and I wasn’t suggesting that every login session reads the shell initialization files in every user’s home directory. I was clearly only talking about the systemwide files.
I have checked a lot, that /etc/profile.d/xx.sh works randomly after reboot/login and exports the env variables or not. This is a new bug! /etc/profile too.
Reboot or login won’t help, but source /etc/profile.d/xx.sh can help.