WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] should ~/.profile really be sourcing ~/.ashrc?  (Read 149 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1881
[Solved] should ~/.profile really be sourcing ~/.ashrc?
« on: July 01, 2026, 10:26:51 AM »
I use the default shell (busybox ash) as my daily driver.

This is in base system's /etc/skel/.profile:

Code: [Select]
if [ -f "$HOME/.ashrc" ]; then
export ENV="$HOME/.ashrc"
. "$HOME/.ashrc"
fi

After I'm logged in and run a GUI terminal emulator, ash runs the commands in .ashrc as expected, but it seems counterintuitive that ash has already inherited everything in .ashrc due to the login shell's sourcing of .ashrc

To see what I mean, here is a little experiment. If I add this to .ashrc:

Code: [Select]
echo "123 $TEST 123"
export TEST="hello world"
echo "123 $TEST 123"

I think the expected output after I reboot and launch a terminal emulator is this:
Code: [Select]
123  123
123 hello world 123

but what I get is this (because login shell already ran .ashrc and passed its environment on to my GUI session):
Code: [Select]
123 hello world 123
123 hello world 123

My understanding of POSIX and ash is that commands in  .profile  are for login shells, while commands in the  ENV  config file (.ashrc in our case) are for interactive shells. I think not sourcing .ashrc in .profile would be clearer, like this:
Code: [Select]
if [ -f "$HOME/.ashrc" ]; then
export ENV="$HOME/.ashrc"
fi
All the different shell configuration files are already confusing enough as it is. I know that a shell can be both "login" and "interactive" at the same time (ugh), but wouldn't it be more conceptually clear if .profile refrained from sourcing .ashrc?
« Last Edit: July 01, 2026, 03:50:41 PM by Rich »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1881
Re: should ~/.profile really be sourcing ~/.ashrc?
« Reply #1 on: July 01, 2026, 10:57:56 AM »
I did a web search and discovered that it is relatively common for people's .profile to source .bashrc (which is analogous to our .profile sourcing .ashrc).

So it seems this is a matter of preference. Oh, well. To me it makes much more sense for ~/.profile to not source ~/.ashrc, so I removed the offending line from my ~/.profile. No ill effects so far, and the relevant behaviors in interactive shells are exactly what I would expect.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1881
Re: should ~/.profile really be sourcing ~/.ashrc?
« Reply #2 on: July 01, 2026, 12:59:02 PM »
Juanito, should I create a pull request on github to change this in /etc/skel/.profile:
Code: [Select]
if [ -f "$HOME/.ashrc" ]; then
export ENV="$HOME/.ashrc"
. "$HOME/.ashrc"
fi
to just this:
Code: [Select]
if [ -f "$HOME/.ashrc" ]; then
export ENV="$HOME/.ashrc"
fi
? (for TCL18)

The advantage is that it seems conceptually cleaner. The disadvantage is that the current .profile has been thoroughly tested over many years in many TCL releases.

If you think this is best left alone, I completely understand.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 15693
Re: should ~/.profile really be sourcing ~/.ashrc?
« Reply #3 on: July 01, 2026, 01:01:24 PM »
@Rich?

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1881
Re: should ~/.profile really be sourcing ~/.ashrc?
« Reply #4 on: July 01, 2026, 01:40:03 PM »
Curaga had this to say: ".(b)ashrc is run on every shell, while .profile is run on login" (https://forum.tinycorelinux.net/index.php?topic=24539.msg155731#msg155731)

If I'm interpreting him correctly, curaga was okay giving special treatment only to login shells. I think he would say that our current /etc/skel/.profile is fine as-is. Do you agree, Rich?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12883
Re: should ~/.profile really be sourcing ~/.ashrc?
« Reply #5 on: July 01, 2026, 02:27:03 PM »
Hi GNUser
I would say you want .ashrc to run because that's where aliases
for commands are often placed.

... I think he would say that our current /etc/skel/.profile is fine as-is. ...
I would say  .profile  is fine as-is.
I can't even find where  /etc/skel/.profile  is being used,

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1881
Re: should ~/.profile really be sourcing ~/.ashrc?
« Reply #6 on: July 01, 2026, 02:45:46 PM »
Hi Rich.
I would say  .profile  is fine as-is.
Thanks for confirming :)

I can't even find where  /etc/skel/.profile  is being used,
The  setupHome  function in /etc/init.d/tc-functions uses the files in /etc/skel.

Thread may be marked as Solved. Sorry for the noise. I thought I had found a problem, but it was a false positive ::)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12883
Re: [Solved] should ~/.profile really be sourcing ~/.ashrc?
« Reply #7 on: July 01, 2026, 03:56:31 PM »
Hi GNUser
That explains it. I was looking for the tree (/etc/skel/.profile) when
I should have been looking for the forest (/etc/skel). :o

Marked as solved. :)