I have an embedded platform running an Arago linux distribution. Right now the only "user" is root but there will eventually be others, but I don't know how many or what user IDs they will have.

Every user of this system must have a particular environment variable exported in order for the GUI to work correctly. I found that if I created and then added the export command to /home/root/.profile it is set correctly for root.

Where should I place the command such that it is exported for every (current and future) user of the system?

Note: On my system, at start up there were no files present in /home/root, I added .bash_profile but that didn't work, then I added .profile and that did work. I thought I might have a dash shell because of that, but when I check /bin/sh it points to bash... so I tagged both.

  • 2
    /etc/bashrc or /etc/profile.d/... – Eddy_Em Feb 13 '14 at 19:57
  • @Eddy_Em - Thanks.. so /etc/bashrc doesn't exist, but /etc/profile.d/ does. There's a couple of shell scripts in there. I take it I just add another one that does an export and that will be autorun? – Mike Feb 13 '14 at 19:59
  • This isn't an unambiguous way: user can delete needed lines from his ~/.bashrc. But you can replace bash by a script that will run bash with needed environment. – Eddy_Em Feb 13 '14 at 20:11
  • 3
    @terdon - That's not a duplicate. That Question is how to get commands run for a specific user, which is why the Q and A's are all talking about ~/.profile, that doesn't solve my problem because I need this command done for all current and future users, which is why it needed to be done in the /etc/profile.d/ area – Mike Feb 14 '14 at 15:05
  • 1
    possible duplicate of Permanent Environment Variable for all users – Braiam Feb 14 '14 at 15:24

Just put the code in a new file in /etc/profile.d/ and check that /etc/profile has some code that executes every script in that directory.

My /etc/profile has:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
  unset i

which means the script needs to have a .sh extension

  • No, just replace for i in /etc/profile.d/*.sh with for i in /etc/profile.d/*. But it will try to run also scripts for other shells (like csh or zsh). – Eddy_Em Feb 13 '14 at 20:08
  • 1
    @Eddy_Em if the OP has a script which has *.sh, touching that script is not a good idea. On the next update of /etc/profile it will get overwritten with one that uses that pattern again, and his script mysteriously would not work anymore. – Anthon Feb 13 '14 at 20:12
  • Why not simply use /etc/profile itself? Why is it better to create a new file in profile.d and source it? – terdon Feb 14 '14 at 14:38
  • @terdon as I indicated in my previous comment to Eddy_Em /etc/profile might be overwritten with some system upgrade, depending on how it got on your computer in the first place. A new script in /etc/profile.d/is less likely to be overwritten. This is not theoretical, I have had that happen with SuSE Linux, although I am not sure if it was /etc/profile or some other file in /etc (that was in, or before, 2000). – Anthon Feb 14 '14 at 14:51
  • OK, so you're assuming that profile always sources the files in profile.d (which seems to be a very reasonable assumption). However, if you need to make changes in profile in order to source profile.d the same argument about being overwritten by a new version stands. – terdon Feb 14 '14 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.