1

I want to try out Bourne shell on FreeBSD so I am starting to set it up for my use.

In .shrc, I set my prompt, enabled vi mode, set some aliases, and exported some variables.

However, I see that .profile also, by default, exports some variables.

It is my understanding that Bourne shell will source .profile on each startup. If so, what is the (historical) reason for having both .shrc and .profile?

Vladimir
  • 169
  • .profile gets sourced at login (or for a login shell). I have never heard of .shrc. Check the Invocation section of the sh man page – glenn jackman May 28 '23 at 03:07
  • "bash" is not the Bourne shell, the closest to which on FreeBSD is shells/heirloom-sh in ports. "bash" is the Bourne Again shell. Please pick one tag and the correct name for what you want. Answers are not the same for the two shells. – JdeBP May 28 '23 at 08:11
  • Psst! If the questioner really wants the Bourne Again shell, @glenn-jackman, then there is actually an explanation for .shrc on FreeBSD. But the questioner has written that xe wants to try the Bourne shell, which one can come close to doing on FreeBSD, and used the [tag:bourne-shell] tag. Taking the questioner at xyr word, and ignoring the self-contradictory [tag:bash] tag, it's actually a different answer entirely. Hence the need for clarification of this poorly worded and ambiguous question. – JdeBP May 28 '23 at 08:22
  • I initially added the 'bash' tag to attract more audience and under assumption that the answer might be similar. I've removed it. To clarify, I am only interested in how Bourne Shell (sh) works --- Bourne Again Shell (bash) was never mentioned in the body of the question. – Vladimir May 28 '23 at 16:01
  • 1
    Related, if not a duplicate - .shinit vs. .shrc – Chris Davies May 28 '23 at 18:02

1 Answers1

1

The closest thing to the Bourne shell, which wasn't really an open source program and cannot be found on pretty much any operating system nowadays, is the Heirloom Bourne shell from OpenSolaris, which is shells/heirloom-sh in the FreeBSD ports collection (usually installed under /usr/ports).

Note that this is not sh. That is (a slightly altered version of) the Debian Almquist shell on FreeBSD.

The Heirloom Bourne shell installs as jsh. This has no dealing with ~/.shrc. It only sources ~/.profile, and that only when it is invoked as a login shell. The only other file that it sources is /etc/profile.

The Bourne shell didn't have all of these complexities that grew up later, with lots of different files. Ironically, it was the C shell, originally a BSD favourite, that kickstarted the trend of all of these other rc files.

The Heirloom Bourne shell isn't quite the Bourne shell. It has job control commands, for instance; which the Bourne shell didn't have because it was written for an operating system that had no such thing. Some of the changes that happened in the history of OpenSolaris mean that this isn't the original Bourne shell. As I said, one cannot get that for any operating system nowadays; and even on the commercial Unices one would have got updated versions of the Bourne shell from roughly the late 1980s onwards, adding in new System 5 Release 4 stuff, just like this one.

So why do you have a ~/.shrc claiming that it's for the Bourne shell and pointing to the sh(1) manual page in a comment?

Basically, that comment is a lie.

sh on FreeBSD and NetBSD is the Almquist shell, FreeBSD using a lightly altered version of the Debian Almquist shell, which was in turn a light alteration of the NetBSD Almquist shell done by Debian people at the turn of the 21st century.

If you look at the sh(1) manual, it tells you that it is the shell written by Kenneth Almquist, not the shell written by Stephen R. Bourne. If you want to try out the Bourne shell, then running sh on FreeBSD will not help you one bit.

That manual also tells you how to manually set up your ~/.profile so that interactive Almquist shells source a ~/.shrc file. This doesn't happen by default in the Almquist shell, where ~/.shrc isn't a standard thing.

~/.shrc is just a conventional file that got dumped into your home directory from /usr/share/skel/ when your home directory was created by pw useradd. It doesn't actually do anything for any shell as standard.

If you want to try out something really esoteric, more so even than the Heirloom Bourne shell, FreeBSD even has the Thompson shell available, as shells/osh in ports.

On the gripping hand, I can recommend trying out and learning the Almquist shell over (or at least before) trying out and learning the Heirloom Bourne shell. It's a lot more useful to know, as all of the #!/bin/sh scripts on FreeBSD of course use it.

The Watanabe shell, shells/yash in ports, is another one worthwhile experiencing. The Watanabe and Debian Almquist shells give the closest tastes of what having only the POSIX-conformant subset of shell behaviours is like, albeit that they both have the non-standard emacs command line editing mode. ☺

JdeBP
  • 68,745
  • thank you so much for not only answering my question but correcting my wrong premise and giving me a lot of historical context. I didn't realize that sh was actually ash on FreeBSD. I am happy to stick with it for now instead of trying the Heirloom Bourne shell. I will thoroughly read the man page. – Vladimir May 28 '23 at 20:21