Advantages of C shell (csh)

For a long time, the C shell (csh) was the default shell in FreeBSD. We all know about the disadvantages of C shell which are listed here:


However, could you point out the positive aspects of using the C shell both as a shell and in scripts?

I don’t ask you to agree with me, but for myself personally, I suggest using the C shell as a shell and at the same time for writing relatively complex scripts (sets of commands with loops, arrays, etc.). And at the same time, completely abandon bash by completely removing it from the computer controlled by FreeBSD. In the case where using the C shell would *really* be undesirable for the reasons listed in the linked article, then we should use Python as a language that can certainly handle everything. In addition, I think that the Mojo language, which is already being developed currently, can replace Python even for system administration tasks and become a truly high-performance alternative to Python. Mojo is based on the LLVM library, just like FreeBSD. If this happens this way, then shell scripts will look completely archaic. But even in this case, the C shell will be useful for utilitarian tasks, because it is native to FreeBSD. Finally, what is archaic (csh) cannot become archaic.

Thus, in this situation, other shells are not so necessary, except in cases where there are legacy scripts that are simply not practical to rewrite.
 
And at the same time, completely abandon bash by completely removing it from the computer controlled by FreeBSD.
Bash isn't installed as part of base and needs to be installed manually from ports. Many scripts use standard sh(1).
then we should use Python as a language that can certainly handle everything.
awk(1) would be a good alternative. It is part of base and fills in that niche between shell scripts and "real" programming languages like C.

Similar to Python, OpenBSD uses Perl for a number of their internal scripts which to this day, I am not convinced by.
 
I've set my user's shell to tcsh(1) ever since I started with FreeBSD (almost 25 years ago). For two reasons, 1) the sh(1) shell was terrible for interactive use (it has improved a lot lately) and 2) it came with the base OS.

I never write scripts with tcsh(1) though, that's the domain of sh(1). If I need to do more complex things I'll pick a proper scripting language, used to do a lot of Perl, nowadays I'd use Python.
 
It's funny to see the differences among people doing the same job. When I started using SunOS in the late nineties one of the first thing my colleagues told me was that you could install bash on it. I never looked back, in the past few years I tried zsh and fish but I always reverted to bash.

[warning - NSFW content]
Even on FreeBSD when I switch to root if i have to write scripts or run more than two or three commands I tend to use bash. Default shell is of course sh, though.
[/warning]
 
  • Thanks
Reactions: dnb
both as a shell and in scripts
You mention both, but mostly refer to scripting.
To me the shell is more than for scripting,...and "sudo pkg install" 🤢

In scripting (t)csh is torture - at least to me.
I do all shell-scripting in sh, or bash.
But except for !#/bin/sh I don't see much of them.

(t)csh are my daily shells, and excluding the browser, or gimp app. 90% of everything I do on my machines I do within and from the (t)csh. Since I've switched from Windows (100% GUI) to FreeBSD I reduce my GUI-usage more and more, and get deeper into shell-usage, and dismantle my GUI more and more (which I don't need goes.)

But to answer your original question:
To me it's simply a question of taste, and personal style of work.
That's the nice thing of FreeBSD: Everybody can setup his or her personal system tailored exactly to individual style, not forced into "one-size-fits-nobody-for-nobody-has-to-have-to-make-the-slightest-effort."

To me csh is neither better, nor worse than sh/bash (besides scripting).
It provides everything I need, I don't miss anything - bash offers lot more features, but I don't need them, I don't want them.
But most of all I'm simply used to csh, have my .cshrc as I like it, etc.
But I also would never force no bash-user to use (t)csh,
as the idea the other way around gives me the creeps.
Not because they are bad, but because I'd have to relearn my habits.
 
  • Thanks
Reactions: dnb
It's funny to see the differences among people doing the same job. When I started using SunOS in the late nineties one of the first thing my colleagues told me was that you could install bash on it. I never looked back, in the past few years I tried zsh and fish but I always reverted to bash.
Yeah, first thing I did to my shiny new Ultra 60 was replace root's shell with bash...and it stopped booting. That version of bash (from Sunfreeware, if memory serves) was dynamically linked to something in /usr which was not mounted immediately at boot.

This is first week at Big New Job in the late '90s, and I'm trying to make a good impression. I learned a lot about Unix over a stressful and sweaty couple of days.
 
  • Thanks
Reactions: dnb
Yeah, first thing I did to my shiny new Ultra 60 was replace root's shell with bash...and it stopped booting. That version of bash (from Sunfreeware, if memory serves) was dynamically linked to something in /usr which was not mounted immediately at boot.

Looks like you placed the system shell, not root's shell.
 
  • Thanks
Reactions: dnb
I've set my user's shell to tcsh(1) ever since I started with FreeBSD (almost 25 years ago). For two reasons, 1) the sh(1) shell was terrible for interactive use (it has improved a lot lately) and 2) it came with the base OS.

I never write scripts with tcsh(1) though, that's the domain of sh(1). If I need to do more complex things I'll pick a proper scripting language, used to do a lot of Perl, nowadays I'd use Python.
This - use csh for interactive use. A working persistent history (without having to configure anything) was what sold me. I don't even change the user's shell, I just type 'csh' after logging / sshing in most places.
Write shell scripts in sh.
 
  • Thanks
Reactions: dnb
This - use csh for interactive use. A working persistent history (without having to configure anything) was what sold me. I don't even change the user's shell, I just type 'csh' after logging / sshing in most places.
Write shell scripts in sh.

I have extensive libraries of shell functions and fragments that I use both in my interactive shells and in scripts. Doesn't work if you use a bourne shell for scripting and *csh or zsh for interactive.
 
  • Thanks
Reactions: dnb
Doesn't work if you use a bourne shell for scripting and *csh or zsh for interactive.
Right.
In some cases it can become a brain-teaser, if you write a sh-, or bash-script should be executed from csh.
It's often but not always about environment variables.
Sometimes one can find ('dirty') workarounds.
In one case I wanted to realize user input by single keys pressed, but simply using read -n 1 didn't work. Search me! It did not work. But it works if I use it within another script which is called by the script.
That 'sub'-script saves the input to a temp-file, from which the 'above'-script is reading again.
May not be very stylish - a deviuos long route, nothing I would dare to show anybody, but such can deliver a working solution fully sufficient for personal usage.

Or one may think of if this were a case for better using something else, e.g. perl.
Some (small, few) things may even quicker, and easier realized with C.
(The sh/bash-syntax is a bit special.)
(I don't mention this for cracauer@, I'm crystal he's way more aware of all of this as I am;
but for potential others, since this an open forum not only read by the posting participators.)

One cannot draw the lines clearly.
It all also depends on individual user needs, demands, knowledge, experience, and last but not least taste.
There is always more than one way to skin a cat.
Seldom one can be claimed the righteous one.
 
  • Thanks
Reactions: dnb
Yeah, first thing I did to my shiny new Ultra 60 was replace root's shell with bash...and it stopped booting. That version of bash (from Sunfreeware, if memory serves) was dynamically linked to something in /usr which was not mounted immediately at boot.

This is first week at Big New Job in the late '90s, and I'm trying to make a good impression. I learned a lot about Unix over a stressful and sweaty couple of days.
Well, I never said I "replaced" the root shell with bash. I "installed" bash so that as soon as I switched to root I executed the "bash" command. I believe that the default root shell was /sbin/sh at that time but I never changed that and neither do it now on my FreeBSD installation.
 
  • Thanks
Reactions: dnb
Well, I never said I "replaced" the root shell with bash. I "installed" bash so that as soon as I switched to root I executed the "bash" command. I believe that the default root shell was /sbin/sh at that time but I never changed that and neither do it now on my FreeBSD installation.
Changing root's shell doesn't impact boot scripts. I'm betting installing bash actually replaced /bin/sh with bash, that would certainly impact all scripts, boot or otherwise.

There seems to be a common misconception that root's shell has anything to do with the way system (boot) scripts are executed.
 
  • Thanks
Reactions: dnb
I believe that in those days in SunOS by default /usr was a different filesystem from / therefore if you replaced the root shell with bash that was installed under /usr/local/bin you'd get stuck with an unbootable system if /usr could not be mounted (and that's why the root shell was /sbin/sh) or / needed an fsck. UFS was not journaled at that time therefore fsck in case of crashes were the norm.
 
  • Thanks
Reactions: dnb
Well, I never said I "replaced" the root shell with bash. I "installed" bash so that as soon as I switched to root I executed the "bash" command. I believe that the default root shell was /sbin/sh at that time but I never changed that and neither do it now on my FreeBSD installation.
I didn't mean any criticism, please forgive the misunderstanding. I often feel my role in life is to serve as a warning to others. I have embraced this role.

 
I've been using Unix with FreeBSD since 2006-2007 (I've never used Linux) and the only shell I use is csh/tcsh. Now in 14.x I set root shell to tcsh, the same as my non-root user. Shell scripts in sh. This is my habit.
 
  • Thanks
Reactions: dnb
Back
Top