Your favorite shell in FreeBSD

I use csh for users and root. I like it because I think it’s fast compared to bash and especially zsh. I used to use zsh and it had some pretty great features but I found it slow. I’m too lame to have any fancy scripting going on, so I think my .cshrc is almost empty. But I have something set up on my server where I can start typing a command and press up to cycle through previous history which starts with whatever I’ve typed so far. It’s awesome. I need to copy that to my other FreeBSD PCs.
 
Why was sh(1) chosen by default in FreeBSD 14.0?

Heads-up discussions (2021-09-22)​

Two lists:

Ultimately (2021-10-20)​

sh(1): make it the default shell for the root user

In the recent history sh(1) has gain the missing features for it to become a usable interractive shell:
  • command completion
  • persistent history support
  • improvements on the default bindings in emacs mode
  • improvements in the vi mode (repect $EDITOR)
  • print a newline when exiting via ^D
  • default prompt and improvements on how PS1 can be configured
  • and more.
This changes also simplifies making tiny freebsd images with only sh(1) as a shell

 
  • Thanks
Reactions: dnb
I like csh and tcsh … can't recall why. A default with PC-BSD, maybe?

… Of the non-indigenous shells, shells/zsh is absolutely outstanding for interactive usage …

I did like the look, and behaviour, during a brief run of GhostBSD in live mode a few hours ago. Part of the screenshot under <https://forums.freebsd.org/posts/646480>.

Unfortunately I don't get the same colours, underlining etc. when I try zsh on FreeBSD (in Konsole).
 
  • Thanks
Reactions: dnb
shells/bash is obviously a Linuxism
Uhm, I don't think so. Bash, by itself, is just a pretty good POSIX/bourne-based shell with lots of nice features. Still fewer than zsh (and also less liberally licensed if that's important for your scenario), but anyways, it's a pretty good shell.

The "linuxisms" attached to it stem from the fact that it's the default shell (also the default POSIX shell, typically available as /bin/sh) in a GNU userland, and people writing "shellscripts" without even being aware they're using bash-specific extensions. I'd say that's not the fault of the shell.

Still, in a perfect world, every advanced user probably ought be comfortable with both of the native shells
I'm not comfortable with any C shell, and I don't intend to ever change that. It has a tradition on BSD, sure, but that doesn't mean I have to like it ;). Thankfully, there's a POSIX shell in base and for everything else, you can install whatever you like from ports :cool:
 
I like your approach. But I couldn't understand whether you use zsh for root as well as for a non-privileged user? Do you run commands as root or do you prefer sudo?

After all, it is extremely inconvenient to change the shell depending on the user. At the same time, using zfs as root is not recommended.
In the past I used CSH/TCSH/SH for root and then switched to ZSH (by typing zsh on the root prompt) to switch to usable shell.

Nowadays I set password for toor user and use /bin/sh shell on toor user and I use ZSH for root account.

I also use sudo/doas (both configured) mostly - but when I need to execute MANY commands as root - like system upgrade - then I switch to root and continue there - its just faster to NOT type sudo/doas prefix for each command.
 
  • Thanks
Reactions: dnb
zsh everywhere it is available: *BSD, MacOS, Linux. rc on plan9. Windows: not needed as they are made of glass :)
I also have:
sh:
if [[ ! -o interactive ]] ; then return; fi
setopt  notify cdablevars autolist autocd recexact \
    longlistjobs histignorespace histignoredups histfindnodups \
    pushdsilent ignoreeof mailwarning
if [[ $UID = 0 ]]; then alias   sw=suspend; else alias   sw=%su; fi
PS1="%* %m:%5. %h%(#.#.:) "
So I can quickly switch between root and normal user & the prompt tells me which context I am in. I have used it since 1994 and I no longer remember what some of these options are for!
 
I would like to have some of the advanced zsh features, but zsh is slightly incompatible with bourne shell syntax, namely in default word splitting. I have extensive libraries of functionality in bourne shell that I use both in scripts and interactively - so I need a fully compatible interactive shell.
Regarding this ... zsh explicitly doesn't guarantee POSIX compliance (which is just a wise thing to do, the more extensions/features you provide, the more likely it is to accidentally violate some POSIX behavior). Still it offers lots of zshoptions(1), and emulation modes setting many of them ... and the emulation mode for sh/ksh is probably close enough to POSIX sh.

Given that, it should be possible to use a library of POSIX shell functions from an interactive zsh (set to "zsh" emulation mode) by just adding a little wrapping layer temporarily setting the "sh" emulation mode for the duration of the function call. Untested, just an idea. ;)
 
I use csh for users and root. I like it because I think it’s fast compared to bash and especially zsh. I used to use zsh and it had some pretty great features but I found it slow.
Explain what you mean by fast and slow. I don't see how a shell can be at all performance-relevant on a modern system.
 
Uhm, I don't think so. Bash, by itself, is just a pretty good POSIX/bourne-based shell with lots of nice features. Still fewer than zsh (and also less liberally licensed if that's important for your scenario), but anyways, it's a pretty good shell.

The "linuxisms" attached to it stem from the fact that it's the default shell (also the default POSIX shell, typically available as /bin/sh) in a GNU userland, and people writing "shellscripts" without even being aware they're using bash-specific extensions. I'd say that's not the fault of the shell.
Yes, you're quite right, that was very careless phrasing on my part. The associated "Linuxisms" do not in fact have anything to do inherently with the shell itself (which I do like a lot and feel very comfortable using!), but with scripts that assume the availability of bash extensions, rely on bash-specific syntax, or use the shebang #!/bin/bash (instead of, say, the more portable #!/usr/bin/env bash). Not the end of the world, but not always great for portability, either.
 
vidmak it's even worse if they use #!/bin/sh and then rely on subtle things that happen to work in bash's "sh emulation" but aren't guaranteed by POSIX at all 😉 -- that's somewhat less common nowadays as many Linux distributions install some more minimalistic shell as /bin/sh, but in a "vanilla" GNU userland, /bin/sh will be provided by bash.

BTW, regarding shebangs, although something like #!/usr/bin/env bash will work in most systems as long as bash is available in PATH, even that isn't fully portable. In fact, no hardcoded shebang is ever fully portable, because POSIX won't guarantee the absolute path to any of its utilities, including the POSIX shell itself. This means if you want to distribute a POSIX shell script in a fully portable way, you have to include some "installer" that finds the POSIX shell and substitutes the shebang on installation... the recommended way to do so is to walk the path returned by getconf PATH looking for a binary named sh.
 
is obviously a Linuxism and by now I am occasionally disappointed to see as a dependency in a port. Heck, even MacOS is now on zsh by default.
Annoyingly zsh has a dependency on perl (on FreeBSD).

From a practical standpoint, bash-static on FreeBSD is a pretty good option (though the port does tend to break a little often and drag in needless dependencies even though it is statically linked!).
 
For root I use csh(1).
For scripting - bash(1) because it's widely spread and many books available.

Some times ago I was surprised when have known that csh(1) doesn't support functions and syntax differs from bash.
Does any know how in bash complete command from history when I have typed some part of command and press UP?
 
Greetings all,

could you please explain the term POSIX compliant shell. I am asking because as I - perhaps incorrectly - understand it, the POSIX standard specifies the minimum that the shell must satisfy. Thus, if the shell satisfies that, but has additional features, is it POSIX compliant?

Kindest regards,

M
 
could you please explain the term POSIX compliant shell.
It fulfills this specification:

Thus, if the shell satisfies that, but has additional features, is it POSIX compliant?
Sure. But it can be pretty hard to offer extensions without breaking some aspect of the POSIX specs. Many capable shells have different modes (including one POSIX-compliant one, or, like zsh, an sh/ksh emulation that's specifically NOT guaranteed to be compliant, but, err, somewhat likely ....)
 
Posix. When i write a shell script for zsh & i use another PC. And that shell script runs under zsh. I'm happy.
If you keep all your scripts to yourself and you have zsh on all the machines relevant for you, that's great and nothing wrong about that. But it's completely irrelevant in the context of portability. Any portable shell script should strictly adhere to POSIX.
 
If you keep all your scripts to yourself and you have zsh on all the machines relevant for you, that's great and nothing wrong about that. But it's completely irrelevant in the context of portability. Any portable shell script should strictly adhere to POSIX.

That's easier said than done. I just discovered that FreeBSD's /bin/sh supports a courtesy bash-ism. When Debian's does not provide that one.
 
Hi zirias@,

thank you for the reply.

I read somewhere that some shells were deemed compliant , but had addition features, hence the question.

Kinest regards,

M
 
Hi bakul,

thank you for your reply.

I know that the standard does not prohibit it. And here is my confusion. Why such an emphasis on POSIX compliant shell, if one POSIX compliant shell has additional feature, incompatible with another shell, and thus a script written using the additional features may be incompatible.

In other words, there is a general recommendation that for compatibility /bin/sh is recommended. Does it imply that /bin/sh has the minimum features required and not more?

Kindest regards,

M
 
Hi bakul,

thank you for your reply.

I know that the standard does not prohibit it. And here is my confusion. Why such an emphasis on POSIX compliant shell, if one POSIX compliant shell has additional feature, incompatible with another shell, and thus a script written using the additional features may be incompatible.

In other words, there is a general recommendation that for compatibility /bin/sh is recommended. Does it imply that /bin/sh has the minimum features required and not more?

Kindest regards,

M

Any additional functionality makes a shell non-compliant.

For example, FreeBSD's /bin/sh accepts `if [ $foo == 42]` , where == is not in the standard, it is '='. The double equal has been added because many scripts have it.

But there could be a script that relies on == throwing an error, and that script would malfunction.
 
Hi cracauer@,

thank you for your reply.

Yes, you gave an example to what I meant. However, your answer is inconsistent with bakul's. Hence, my (continuing) confusion.

My initial understanding was that POSIX compliant shell is the one that implements only the minimum prescribed by the standard, because doing more, would lead to an inconsistency, as you pointed out.

Kindest regards,

M
 
Back
Top