You are not logged in.
Pages: 1
Hi there!
Just decided to join this amazing community, and have a simple question as as newbie:
How to set environment variables and alias while my default shell is /bin/sh, rather than /bin/bash
Since on some other OSes, it is feasible with ~/.shrc file, but this since doesn't work in Arch.
Could anyone give some advices? Thanks!
Last edited by michaelll (2022-03-11 11:33:23)
Offline
What is raw /bin/sh in your case? /bin/sh is not the actual original sh in almost any cases, on Arch it defaults to a symlink to bash which will relevantly adjust it's behaviour if it is invoked as such. The default files it will check in that case are /etc/profile and ~/.profile
Last edited by V1del (2022-03-11 12:14:50)
Offline
If bash is invoked with the name sh, it tries to mimic the startup behavior of historical
versions of sh as closely as possible, while conforming to the POSIX standard as well.
When invoked as an interactive login shell, or a non-interactive shell with the --login
option, it first attempts to read and execute commands from /etc/profile and ~/.profile,
in that order. The --noprofile option may be used to inhibit this behavior. When invoked
as an interactive shell with the name sh, bash looks for the variable ENV, expands its
value if it is defined, and uses the expanded value as the name of a file to read and exe‐
cute. Since a shell invoked as sh does not attempt to read and execute commands from any
other startup files, the --rcfile option has no effect. A non-interactive shell invoked
with the name sh does not attempt to read any other startup files. When invoked as sh,
bash enters posix mode after the startup files are read.
on some other OSes, it is feasible with ~/.shrc file
Aha. "Some".
https://xkcd.com/285/
Online
I suspect "some" other OSes ship a default /etc/profile (or even create a ~/.profile) which includes "ENV=~/.shrc"
I use ash as my shell and as /bin/sh, and have added an ENV setting to ~/.profile for this purpose.
Last edited by Trilby (2022-03-13 02:07:52)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
What is raw /bin/sh in your case? /bin/sh is not the actual original sh in almost any cases, on Arch it defaults to a symlink to bash which will relevantly adjust it's behaviour if it is invoked as such. The default files it will check in that case are /etc/profile and ~/.profile
Thanks for the clarification @V1de, now I'm able to configure the shell as you suggested ![]()
Offline
I suspect "some" other OSes ship a default /etc/profile (or even create a ~/.profile) which includes "ENV=~/.shrc"
I uses ash as my shell and as /bin/sh, and have added an ENV setting to ~/.profile for this purpose.
Thanks for the guide! I look through those OSes' man page again, and it is true as you said.
BTW, I got to admit that this community is much more warmer than those of "some other" OSes. How could the novices like me become a faithful user when the maintainers / moderators / fellow members choose to be silent when we need helps? I cannot even convince myself that those "some other" OSes are Open Source. Whatever, I choose to stay here, not only the Simplicity of Arch, but the warmness of community.
Offline
Pages: 1