You are not logged in.

#1 2022-03-11 11:33:02

michaelll
Member
Registered: 2022-03-11
Posts: 3

How to set env/alias for raw /bin/sh?

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

#2 2022-03-11 12:13:15

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,285

Re: How to set env/alias for raw /bin/sh?

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

#3 2022-03-11 14:31:59

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,743

Re: How to set env/alias for raw /bin/sh?

man bash wrote:

       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

#4 2022-03-11 14:38:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: How to set env/alias for raw /bin/sh?

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

#5 2022-03-13 01:45:35

michaelll
Member
Registered: 2022-03-11
Posts: 3

Re: How to set env/alias for raw /bin/sh?

V1del wrote:

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 smile

Offline

#6 2022-03-13 02:05:43

michaelll
Member
Registered: 2022-03-11
Posts: 3

Re: How to set env/alias for raw /bin/sh?

Trilby wrote:

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

Board footer

Powered by FluxBB