# Default shell?



## Greg Fitzgerald (Mar 25, 2020)

What is everyone using as there default shell. I currently use zsh, but I wonder if anyone is just using /bin/sh or if tcsh is good enough for daily usage? Just looking for others opinions on the matter.

Looks like /bin/sh is Bourne Shell? Hows this differ from Bash?


----------



## Alain De Vos (Mar 25, 2020)

I use zsh as root shell an user shell.
And mksh as toor shell, installed in /bin, in case something would be broken and allowing me to recover.
I don't think changing to bash is an improvement, or I would not know for what.


----------



## ralphbsz (Mar 25, 2020)

Bourne shell is a predecessor of bash. Bash is the old Bourne shell having gone through the GNU treatment, adding lots of functionality.

I use bash consistently on all machines, even FreeBSD. Why? Because for shell scripts, the old bourne shell is much better than (t)csh. And I want the language in which I write shells scripts to be the same that I use at the command line everyday, so I am and stay familiar with the syntax (old joke, beware of the man who has only one gun, because he knows how to use it). For shell scripts, I usually go back to using /bin/sh (which is a subset of bash), and trying to use only features that were in V7 standard sh, but interactively, I enjoy the modern features of bash too much (even though I don't them in scripts). Ideally, I could use ksh or zsh or any of the myriad other extensions of the Bourne shell (all of the best ones seem to be derived form the Korn shell these days), but bash is trivially present on all machines I use at work, without having to do any installs there, and at work I use lots of computers, so installing something there would be a BIG hassle.

So, is it a good idea to use bash on FreeBSD? Probably not, because it is non-base optional software. For me, the benefits outweigh the negatives. Other people may not want to follow my example.

And then I go even one step further, and do something that I explicitly recommend people NOT do: I change the default shell of root on my FreeBSD machines to also be bash! I always create a toor account that has tcsh, for emergencies. I know that this will bite me one of these days, but I know how to get out of that pickle if I need to.

I think your choice of zsh is perfectly sensible, but that's really a personal choice. Just make sure you have an account like toor that uses a shell that ships in the base system, in case everything comes apart at the seams.


----------



## mark_j (Mar 25, 2020)

TCSH FTW!


----------



## SirDice (Mar 25, 2020)

I use tcsh(1) for interactive use (user's shell) and sh(1) for scripting.



Greg Fitzgerald said:


> Looks like /bin/sh is Bourne Shell?


Strictly speaking, FreeBSD's sh(1) is actually Almquist shell but it's a Bourne compatible shell.


----------



## Greg Fitzgerald (Mar 25, 2020)

Thank you everyone. SirDice ok I know of ash shell. Why tcsh over sh? Is tcsh more powerful in some way?


----------



## SirDice (Mar 25, 2020)

Greg Fitzgerald said:


> Why tcsh over sh? Is tcsh more powerful in some way?


For interactive use the sh(1) shell is, ehrm, kind of spartan. tcsh(1) on the other hand has all the nice features you want with a interactive shell, like command history. Nowadays sh(1) has some command history too, but it's fairly rudimentary and, for lack of a better description, spartan.

But, try a couple of shells, some people like bash, I personally don't. Others are quite fond of zsh, old UNIX-beards often use a Korn shell (or a variant thereof). I just like to stick to whatever is in the base and have gotten used it.


----------



## mickey (Mar 25, 2020)

For everything interactive I have been using tcsh(1) for ages and don't expect that to change anytime soon. For scripting I prefer to use sh(1) though.


----------



## mark_j (Mar 25, 2020)

Isn't it also what you started out with? For me it was csh then tcsh and I've never bothered to change. For non-interactive, it's sh because I'm not a huge fan of nuances of tcsh like ${?variable} and its pedant*r*y with spaces, eg $a==$b. Bzzt!

I can operate interactively in sh but only a short while before I grow frustrated with no pushd/popd


----------



## SirDice (Mar 25, 2020)

mark_j said:


> For non-interactive, it's sh because I'm not a huge fan of nuances of tcsh like ${?variable} and its pedanty with spaces, eg $a==$b. Bzzt!


For scripting purposes the C shells are an absolute horror show. Mostly because of the weird redirections but there are a lot of other quirks too. Really old document but still holds true to this day: Csh Programming Considered Harmful


----------



## ShelLuser (Mar 25, 2020)

I'm using the Korn shell (shells/pdksh) for my own account because I enjoy the enhanced interactive options in comparison to the regular /bin/sh (I'm always using vi mode). Root remains to the default csh because I prefer having something blocking me from using shell commands I'm familiar with without thinking. So if I try to use a "for a in *txt[/file] I'd get an error because csh requires foreach.

All other users on the server (not many) get /bin/sh, also because they can always change their own shell if they want to. However, no Bash on this setup.


----------



## zirias@ (Mar 25, 2020)

Greg Fitzgerald said:


> What is everyone using as there default shell. I currently use zsh, but I wonder if anyone is just using /bin/sh or if tcsh is good enough for daily usage?


My default shell is zsh as well, as it's probably the most capable bourne shell out there. I might be an alien in the FreeBSD community, but I don't want to touch a C shell -- doesn't make sense to me to use a different syntax/grammar in interactive use than in scripts.

On some virtual machines where I only have to to a few administrative tasks now and then, I don't bother installing zsh and just use /bin/sh.


----------



## Hakaba (Mar 25, 2020)

Root and script : sh.
User : zsh
In all my computer.

And when I have a mission with bash script, I transform it to sh.

Using bash to deploy something to a server is not a good idea. Ubuntu default shell (dsh ?) do not reconize «source».
But where is the world «source» is easiest to use than «.»(dot) ?


----------



## wolffnx (Mar 25, 2020)

I never change the root shell... but for me bash,in my servers and mi desktops


----------



## Greg Fitzgerald (Mar 25, 2020)

ShelLuser I been playing with mksh today myself. I'll have to also look at pdksh


----------



## ehanneken (Mar 25, 2020)

For scripts: POSIX shell. (/bin/sh seems compliant.)
For interactive use: Bash, because why not? It's a Bourne-like shell with support for history and auto-completion.
For root: I just leave it with /bin/tcsh.

I did use Korn shell (ksh88 mostly) for many years while I was programming on HP-UX and Solaris, but for a long time it was a hassle to install it on FreeBSD, and Bash seemed fine.


----------



## SirDice (Mar 25, 2020)

ehanneken said:


> For root: I just leave it with /bin/tcsh.


The default shell for root is actually csh(1), not tcsh(1). Although both do refer to the same executable (they're hard-linked) there are feature differences between the two invocations.


----------



## PMc (Mar 25, 2020)

I got used to bash when I did use Linux, and then it stayed.
But for scripting I strictly use /bin/sh, mainly because they should work without ports installed or /usr/local mounted. I don't bother with the shell's scripting features (regexps, arrays, etc.) and use sed and awk for the more difficult operations. I would like to use more ruby there, but it's the same downside: it is in ports.


----------



## mark_j (Mar 25, 2020)

PMc said:


> I got used to bash when I did use Linux, and then it stayed.


Edit your sig, communcation  to communication.
Sorry for being a spelling nazi...


----------



## athan (Mar 26, 2020)

(T)CSH as interactive shell for four reasons

BSD=CSH=BSD
It is in base
Its interactive features have always been better than Bash's
It is the login shell I'm using since early '90s 
As for scripting, honestly I can't think of any reason to use anything other than the sh shell the system uses for its own scripts.


----------



## Greg Fitzgerald (Mar 26, 2020)

Anyone here have their tcsh dotfiles online?


----------



## Deleted member 48958 (Mar 26, 2020)

Greg Fitzgerald said:


> Anyone here have their tcsh dotfiles online?


Read this topic - https://forums.freebsd.org/threads/share-your-tcshrc-file.21040

Personally I'm using shells/zsh as my default shell, It has much more features than tcsh,
also it's working faster IMO. See this thread if you want to create your zshrc file -
https://forums.freebsd.org/threads/share-your-zshrc-file.62653


----------



## PMc (Mar 26, 2020)

mark_j said:


> Edit your sig, communcation  to communication.
> Sorry for being a spelling nazi...



You're welcome indeed. I didn't see that piece - just found it was switched off in prefs.


----------



## phalange (Mar 26, 2020)

Greg Fitzgerald said:


> What is everyone using as there default shell.



I use fish.  And sometimes sh.


----------



## gpw928 (Mar 26, 2020)

Most people are just going to prefer the shell with which they get most familiar.  For interactive use, you are going to want one with good history editing. 

If CPU cycles matter (they rarely do for interactive use), then bash is an utter pig.  It's pretty heavy on memory too.  Also, its interactive history editing is frequently criticised as clumbsy (because it is).

When you are in single user mode, in full emergency response, you don't want to be struggling with an unfamiliar shell, particularly since the man pages won't be available.

For those reasons I keep a statically linked copy of my favourite shell in the root (and use it as the root shell).  For historical reasons, that happens to be ksh.  It might just as easily been zsh.

I generally script in /bin/sh, but stick to the V7 Bourne shell syntax for portability (dash compatibility matters to me because I use Debian nearly as much as I use FreeBSD).

If I think my shell script needs arrays, hashes, or anything not available in the original Bourne shell, I switch to perl (because it's portable and I'm comfortable with it).  Others may choose python.

However I have been known to script in bash, very occasionally.  It generally happens when I get part way through a shell script, realise it's more complex than originally thought, and I'm just too lazy to switch to perl.


----------



## grahamperrin@ (Dec 29, 2020)

SirDice said:


> The default shell for root is actually csh(1), not tcsh(1). …


https://www.freebsd.org/doc/en_US.ISO8859-1/articles/linux-users/shells.html is outdated:


> … FreeBSD uses tcsh(1) as the default root shell, and the Bourne shell-compatible sh(1) as the default user shell. …


The defaults are now csh(1) for root and tcsh(1) for user, true?

At a glance, is anything else outdated at the page above?

I think it will be useful to have the two defaults mentioned near the head of https://www.freebsd.org/doc/handbook/shells.html


----------



## T-Daemon (Dec 29, 2020)

grahamperrin said:


> The defaults are now csh(1) for root and *tcsh(1) for user*, true?


According to adduser(8)'s shell script, currently the default shell for users is /bin/sh. adduser.sh head (CURRENT), releng/12.2 (12.2-RELEASE).


----------



## Argentum (Dec 29, 2020)

phalange said:


> I use fish.  And sometimes sh.


Same here. I have *bash* and *fish* installed on all machines. Gradually moved from bash to fish. Now it is already a must to have.* Like it.*

shells/fish


----------



## grahamperrin@ (Dec 29, 2020)

T-Daemon said:


> According to adduser(8)'s shell script currently the default shell for users is /bin/sh. adduser.sh head (CURRENT), releng/12.2 (12.2-RELEASE).


Thanks! 

Embracing the new, main and stable/12: 






						adduser.sh « adduser « usr.sbin - src - FreeBSD source tree
					






					cgit.freebsd.org
				









						adduser.sh « adduser « usr.sbin - src - FreeBSD source tree
					






					cgit.freebsd.org


----------



## JMOR (May 4, 2021)

Maybe this is not the proper place for pointing this out. But the following page in the documentation also has the default shells in FreeBSD wrong:









						FreeBSD Quickstart Guide for Linux® Users
					

This document is intended to quickly familiarize intermediate to advanced Linux® users with the basics of FreeBSD.




					docs.freebsd.org
				




"Instead, FreeBSD uses tcsh(1) as the default root shell, and the Bourne shell-compatible sh(1) as the default user shell"

As it was already mentioned in this thread, the correct information is: csh for root, tcsh for unprivileged users.


----------



## SirDice (May 4, 2021)

/bin/tcsh and /bin/csh are the exact same executable.

The default user shell is whatever you set in /etc/adduser.conf (if that file doesn't exist it defaults to /bin/sh).


----------



## eldaemon (May 4, 2021)

I've used bash for years and recently shifted to zsh. toor account with say /bin/sh is a good idea.

/bin/sh feels way too light for serious use, /bin/tcsh catches me by surprise a lot.


----------



## SirDice (May 4, 2021)

I have set my user's shell to tcsh(1) many years ago. For the sole reason it's part of the base OS so it's always available. I've now grown so accustomed to it I can't do without any more.


----------



## JMOR (May 4, 2021)

SirDice said:


> The default user shell is whatever you set in /etc/adduser.conf (if that file doesn't exist it defaults to /bin/sh).


You are right, the default shell for a new user is sh (I made a clean install and there is not /etc/adduser.conf by default). I didn't remember I was the one setting tcsh when I created my regular user account (this is my home PC). So, I was wrong when I said " tcsh for unprivileged users", and the documentation is fine there.
I will maintain though that the part of the root shell would have a more accurate wording if it said that the default shell for root is csh (I am pretty sure I was only asked for root's password when installing). Yes, now I know, thanks to you, that they are the same executable. But a newbie like myself who reads that and checks his root's account shell, if he is not aware of this technicality, may think there is a typo in the documentation.

By the way, I finally settled for sh for root (and scripting) and zsh for my regular account (zsh is the one I had when I was using Linux).


----------



## grahamperrin@ (May 5, 2021)

JMOR said:


> … the documentation …
> 
> 
> 
> ...



<https://docs.freebsd.org/en_US.ISO8859-1/articles/linux-users/shells.html> is an outdated edition. I had no knowledge of this when I posted my earlier comment, sorry. 

Please begin at the FreeBSD home page to find a current edition.


----------



## bsduck (May 5, 2021)

I'm fine with /bin/sh for my basic usage and prefer it over tcsh. Tried fish but I don't like it, it's too interactive and non-standard to my taste. Bash feels very similar to sh. Zsh looks interesting but I'm somewhat confused by its numerous options, I still have to give it a more serious try.


----------



## Menelkir (May 5, 2021)

I've worked with AIX for years so I tend to use shells/pdksh or shells/ksh93, some time ago I've discovered shells/mksh and I find it pretty nice. For any other purposes, shells/bash is fine to me. For root, csh is pretty much fine.


----------



## Alain De Vos (May 5, 2021)

zsh has all features by default. So it is a simple interactive shell.
For scripts it is flexible.


----------



## memreflect (May 6, 2021)

For daily use, I personally use shells/rc, though it has its own pitfalls (e.g. variables are globally persistent unless bound to a command and are automatically exported).

When I log in as toor, shells/fish helps me get things done more quickly, but it has too many features for me to use it beyond occasional usage; I leave root's default /bin/csh shell alone.

If you want to stick with familiar sh syntax, many seem happy with shells/bash, shells/zsh, or even one of the ksh variants like shells/ast-ksh.

Of course, after a system upgrade like 12.2-RELEASE→13.0-RELEASE where there's some library incompatibility, the only shells available are sh and tcsh.  I use sh on FreeBSD just like I use Internet Explorer on Windows: it's useful enough to let me install the software I actually want to use.


----------



## rorgoroth (May 6, 2021)

I've used tcsh for years across bsd and linux and have no plans to change away from it. I do however never use it for scripts and always use dash/sh for those.


----------

