Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: sh not sourcing .bashrc or /etc/profile or /etc/bash/* (Read 1130 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

sh not sourcing .bashrc or /etc/profile or /etc/bash/*

I fresh installed Artix (runit) couple days ago and I'm having trouble with bash. I tried searching for a couple hours but didn't find anything relevant or anything that solved my problem.
While using the /bin/bash everything works fine, but when trying to use /bin/sh instead, it simply doesn't source the ~/.bashrc file.

/bin/bash sources ~/.bashrc just fine (see PS1).
Code: [Select]
look@yuria in ~ $: bash
look@yuria in ~ $:

/bin/sh doesn't.
Code: [Select]
look@yuria in ~ $: sh
sh-5.1$

I can source .bashrc directly with /bin/bash
Code: [Select]
look@yuria in ~ $: bash
look@yuria in ~ $: source .bashrc
look@yuria in ~ $:

I cannot source .bashrc directly with /bin/sh (yes I am at home directory).
(I can source .bashrc if I specify the current directory - see PS1)
Code: [Select]
look@yuria in ~ $: sh
sh-5.1$ source .bashrc
sh: source: .bashrc: file not found
sh-5.1$ source ./.bashrc
look@yuria in ~ $:

which location seems just fine
Code: [Select]
look@yuria in ~ $: which bash
/usr/bin/bash
look@yuria in ~ $: which sh
/usr/bin/sh

Yes, sh is symlinked to bash
Code: [Select]
look@yuria in ~ $: ls -lhF /usr/bin/sh
lrwxrwxrwx 1 root root 4 Nov 19 14:27 /usr/bin/sh -> bash*
look@yuria in ~ $: ls -lhF /usr/bin/bash
-rwxr-xr-x 1 root root 1.1M Oct 18 11:29 /usr/bin/bash*

Additionally /bin/sh doesn't seem to source /etc/profile or /etc/bash/bashrc or /etc/bash/bashrc.d/artix.bashrc, but /bin/bash does.
I have no idea why this is happening since sh is simply symlinked to bash, shouldn't it be the same? And yes I tried redoing the symlinks for /bin/sh with the absolute path to no success.
I usually can solve most of my distro problems by searching or by my own experience but I really don't get what is going on.
I simply would like for sh to act as an alias for bash since its the shell I want to use.
Please tell me if you need any more information or if there are any posts solving this issue.
Thanks.

Re: sh not sourcing .bashrc or /etc/profile or /etc/bash/*

Reply #1
>While using the /bin/bash everything works fine, but when trying to use /bin/sh instead, it simply doesn't source the ~/.bashrc file.

That's because /bin/sh and /bin/bash while symlinked, refer to completely different shells.

/bin/sh is supposed the bourne/POSIX shell, THE standard shell of UNIX operating systems, everything from Linux to the BSDs, proprietary ones like Solaris, HP-UX, AIX, QNX and the historical ones like research UNIX and 4.X BSDs and whatever dozen of UNIXes that are either forgotten or still alive.

The reason /bin/sh doesn't read any kind of bashrc file is because it's not the same as the bash shell and is not supposed to act like one.

When bash is started as /bin/sh, it goes into POSIX Mode and reads /etc/profile, ~/.profile and reads whatever file is stored in ENV environment variable if it's a login shell.

> I usually can solve most of my distro problems by searching or by my own experience but I really don't get what is going on.

That sort of thing requires a bit of historical knowledge  : )
Also take a look at the man page for bash(1).

> I simply would like for sh to act as an alias for bash since its the shell I want to use.

It's better not to do that since like I said above, they are not the same shell.

Re: sh not sourcing .bashrc or /etc/profile or /etc/bash/*

Reply #2
Even though symlinked the executable can read the command used to run it and act accordingly.
For example look at busybox. Loads of symlinks to the same executable but they do entirely different things.

sh is not bash. I'm not sure of the differences other than sh is more basic and POSIX compliant
If you want bash why not just use bash ?

Edit: Ninja'd :)

Re: sh not sourcing .bashrc or /etc/profile or /etc/bash/*

Reply #3
> /bin/sh is supposed the bourne/POSIX shell, THE standard shell of UNIX operating systems, everything from Linux to the BSDs, proprietary ones like Solaris, HP-UX, AIX, QNX and the historical ones like research UNIX and 4.X BSDs and whatever dozen of UNIXes that are either forgotten or still alive.

Thank you so much for the explanation.

> If you want bash why not just use bash ?

Will do, thanks.