# What shell does the *operating system itself* use?



## rivercat (Jun 3, 2009)

I know tcsh & sh are defaults for root & users, but what does freeBSD use for it's own tasks?
Such as system start-up and package management...
I'd like to use the same shell so that there would be just one shell on my system.
I.e. what is the one shell that musnt be removed because the OS uses it?

I hope this makes sense; I searched alot, but could only verify that some rc scripts use sh.
thanks


----------



## DutchDaemon (Jun 3, 2009)

```
# grep -r ^"\#\!" /etc /usr/bin /bin /sbin /usr/sbin | grep -c /bin/sh
268
# grep -r ^"\#\!" /etc /usr/bin /bin /sbin /usr/sbin | grep -vc /bin/sh
3
```

Those 3 are perl.


----------



## vivek (Jun 3, 2009)

+ system start-up done via /bin/sh
+ */rc.d/* done via /bin/sh
+ most package management tools are written in C or perl or other shell scripting.


----------



## SirDice (Jun 3, 2009)

vivek said:
			
		

> + system start-up done via /bin/sh


Actually it's more or less a simple Forth (boot(8) and loader(8)).


----------



## SirDice (Jun 3, 2009)

rivercat said:
			
		

> I'd like to use the same shell so that there would be just one shell on my system.
> I.e. what is the one shell that musnt be removed because the OS uses it?


That would be /bin/sh but unless you enjoy a rather spartan shell I suggest setting your shell to /bin/tcsh.


----------



## Oko (Jun 3, 2009)

SirDice said:
			
		

> That would be /bin/sh but unless you enjoy a rather spartan shell I suggest setting your shell to /bin/tcsh.


Are you trying to start a flame war I like better Korn (OpenBSD) or Mir Korn shell (mksh) on FreeBSD. Actually to go back to original question /bin/sh is a Posix shell. He needs to have sh to be able to execute scripts.


----------



## SirDice (Jun 3, 2009)

Oko said:
			
		

> Are you trying to start a flame war


Not really :e but (t)csh has been the 'standard' shell on freebsd for users since I can remember. 



> I like better Korn (OpenBSD) or Mir Korn shell (mksh) on FreeBSD.


Never could get the hang of Korn but then again I never have put much effort into it :r


----------



## rivercat (Jun 3, 2009)

Dammit.
It was because of (ba)sh that was considering leaving Slackware linux. sh seemed bloated and inconsistent.
Then I find out "freeBSD's default for root is tcsh", and think I've found my solution.

Can anyone name a distro that uses the smallest/lightest shell? zsh? ash?


----------



## rivercat (Jun 3, 2009)

DutchDaemon said:
			
		

> ```
> # grep -r ^"\#\!" /etc /usr/bin /bin /sbin /usr/sbin | grep -vc /bin/sh
> 3
> ```
> Those 3 are perl.



You mean even perl is a nescessity for freeBSD to run?


----------



## rivercat (Jun 3, 2009)

Oko said:
			
		

> I like better Korn (OpenBSD) or Mir Korn shell (mksh) on FreeBSD.



Is Korn the _only_ shell required for OpenBSD?

For FreeBSD, would Mir Korn (mksh) suffice as the _only_ shell?


----------



## fronclynne (Jun 3, 2009)

rivercat said:
			
		

> You mean even perl is a nescessity for freeBSD to run?


Run it without the -c flag:

```
# grep -r ^"\#\!" /etc /usr/bin /bin /sbin /usr/sbin | grep -v /bin/sh
/usr/bin/mmroff:#! /usr/bin/perl
/usr/bin/afmtodit:#! /usr/bin/perl -w
/usr/sbin/ntptrace:#! /usr/local/bin/perl -w
#
```
So, no.  But to use those three tools, yes.


----------



## SirDice (Jun 3, 2009)

rivercat said:
			
		

> It was because of (ba)sh that was considering leaving Slackware linux. sh seemed bloated and inconsistent.


Do realize that _every_ unix and unix-like system supports (and uses!) the Bourne shell (that's /bin/sh). So if you want portability the Bourne shell is the rule (OpenBSD also relies on the Bourne shell; /bin/sh for it's startup scripts). Also realize that the /bin/sh on most linux systems is actually the Bourne Again shell (that's /bin/bash) with the 'extra' features turned off, hence the 'bloated' /bin/sh.



> Then I find out "freeBSD's default for root is tcsh", and think I've found my solution.


Yes, but don't even think about removing /bin/sh!



> Can anyone name a distro that uses the smallest/lightest shell? zsh? ash?


Zsh certainly isn't small by any standards. It's also not part of the base system, neither are ash, mksh and bash. This means you will have to install additional ports if you want them. So I'd say stick to FreeBSD :e

Why are you so concerned about a few KB when the whole system takes up much more than that?


As a side note, perl isn't part of the base system anymore so any pkgtool that's part of the base OS cannot use perl.


----------



## mjkerpan (Jun 4, 2009)

Just a note: the /bin/sh present in FreeBSD is NOT actually the Bourne Shell, it's the POSIX shell. The Bourne Shell came from AT&T and thus had to be replaced when in order for BSD to be releasable to people who didn't have a source license from Bell Labs. While the Bourne Shell was eventually open sourced along with the rest of 7th Edition Unix, that was over a decade after it had been replaced in the various BSDs...


----------



## rivercat (Jun 4, 2009)

SirDice said:
			
		

> Why are you so concerned about a few KB when the whole system takes up much more than that?


I was hoping tcsh would be easier to learn than sh, since I had some C exposure. I hate it when languages use different syntax for the same constructs.

fi?
esac?
God what was wrong with ) or }x(
Bash doesnt seem to 'Keep it simple stupid'.

Thanks for helping a newb though...


----------



## monkeyboy (Jun 4, 2009)

rivercat said:
			
		

> I was hoping tcsh would be easier to learn than sh, since I had some C exposure. I hate it when languages use different syntax for the same constructs.
> 
> fi?
> esac?
> ...


Steve Bourne was an Algol 68 fanatic...

But he also (rightly I think) didn't want to make his shell too foreign for the simple routine stuff.

Can you imagine having to type
$ ls();

instead of
$ ls

or
$ cat(a, b, c) | tr();

instead of
$ cat a b c | tr

He obviously decided not to tackle expressions either.

And I think it was right not to use {} for blocks...

The shell does a lot of string processing, and C is a pretty terrible language for that...

Basically Bourne keep nearly all of the V6 shell syntax for command line processing (pipelines, metacharacters, string substitution, etc), but completely overhauled the flow control aspects of the V6 shell, which were practically non-existent anyways (remember goto(1), which does a seek() followed by a search for a : label)?


----------



## Oko (Jun 4, 2009)

rivercat said:
			
		

> Is Korn the _only_ shell required for OpenBSD?
> 
> For FreeBSD, would Mir Korn (mksh) suffice as the _only_ shell?


No of course not. How are you going to run scripts? We went over that. Every POSIX complaint system must have POSIX version of sh. All scripts should be written in sh. On the top of that system usually have one maybe two other shells. In OpenBSD that other shell happens to be Public Korn Shell (pksh) which is heavily patched for security reasons. It is de-facto OpenBSD version of public korn shell. Mir Korn is another free implementation of Korn Shell. Default OpenBSD installation contains third shell (csh). It is original Berkeley implementation 
of C shell.

If you are on proprietary Unix you can use Korn93 shell which is very, very good. 

NetBSD default shell is just sh. 

As you heard before FreeBSD default shell is tcsh.It is not good idea to replace default shell for root account! There are lots of threads about that on this forum.


----------



## mjkerpan (Jun 4, 2009)

Oko said:
			
		

> If you are on proprietary Unix you can use Korn93 shell which is very, very good.


Ksh93 has been FOSS for a number of years. There's no need to be on a proprietary system to use it. It's in the ports tree even. It didn't build correctly for me


----------



## DutchDaemon (Jun 4, 2009)

Try it with -DNO_PROPRIETARY_UNIX.

(seriously, don't bother..)


----------



## Oko (Jun 4, 2009)

mjkerpan said:
			
		

> Ksh93 has been FOSS for a number of years. There's no need to be on a proprietary system to use it. It's in the ports tree even. It didn't build correctly for me





> Q8.	Is KornShell public domain?
> A8.	Yes, the language description is public domain and
> can be reimplemented.  Some of the KornShell language
> features have been reimplemented in the GNU shell, bash
> ...



I guess that probably explains why it failed to build for you


----------



## phoenix (Jun 4, 2009)

SirDice said:
			
		

> Not really :e but (t)csh has been the 'standard' shell on freebsd for users since I can remember.



The default shell for non-root users has been /bin/sh since pretty much the dawn of time.  The default shell for root user(s) is /bin/tcsh.  At least, that's the defaults for sysinstall and adduser.


----------



## morbit (Aug 12, 2009)

> Can anyone name a distro that uses the smallest/lightest shell? zsh? ash?



Lightest shell would be http://www.freshports.org/shells/rc/I think. Lightest interactive - mksh/pdksh?


----------



## _martin (Apr 12, 2011)

rivercat said:
			
		

> It was because of (ba)sh that was considering leaving Slackware linux.



Mhm - that is one weird reason why to leave Slackware.

Write scripts in posix shell (/bin/sh), you should have no problems porting them anywhere. It should resist even evil /bin/sh being a symlink to something else on Linux. 

Personally I write scripts in posix shell, but I do use either bash or korn shell (shells/ksh93) with vi mode set on as a user shell.


----------



## SirDice (Apr 13, 2011)

I'm sure the OP figured it out after almost 2 years. Please look at the date before replying.


----------



## poh-poh (Apr 14, 2011)

Oko said:
			
		

> /bin/sh is a Posix shell.


No, it's more of a superset. Some extensions are tolerated, e.g. prompt escapes (r142845), filename completion (r209221), *[ foo == bar ]* (r219084), *$'quoting'* (soon, see PR bin/156306).


----------



## mirabilos (Apr 24, 2013)

Oko said:
			
		

> No of course not. How are you going to run scripts? We went over that. Every POSIX complaint system must have POSIX version of sh.



Actually, FreeBSDâ€™s /bin/sh is not a POSIX sh. In some points, it even goes _against_ what POSIX requires.

If you compile mksh with the following options:

-DMKSH_MIDNIGHTBSD01ASH_COMPAT (enable compatibility to MidnightBSD 0.1 ash (/bin/sh) when `set -o sh` is run)
-DMKSH_BINSHREDUCED (imply `set -o sh` when the shell is called as sh or -sh as its last path component)
Then I believe itâ€™s possible to run a FreeBSDÂ® system with only the resulting mksh binary, installed in /bin/mksh and hardlinked in /bin/sh (or just installed as /bin/sh but whoâ€™d want that? â˜º).


----------



## drhowarddrfine (Apr 24, 2013)

SirDice said:
			
		

> I'm sure the OP figured it out after almost 2 years. Please look at the date before replying.



To infinity...and beyond!!


----------

