[OT] What shells do you prefer to use for interactive / scripting use?

When I was a student and mainly used Linux as a desktop machine, I used tcsh for both terminals (interactive use) and job scripts. After that, I started to use Mac OSX (Snow Leopard), and because the default shell was bash, I learned its usage and have been still using it today (for both Terminal and job scripts). However, newer MacOS changed the default shell from bash to zsh for some reason… Because I am now trying to set up new MacOS, this may be a good opportunity to try a new shell (not limited to zsh but also other shells).

So, for this purpose, can I ask your opinions & experiences about your favorite shell(s) for (1) daily interactive use (terminals) and (2) job batch scripts, with particular interest in numerical computing and data pre/post processing etc? For example, I am interested in the functionality like this (which bash also has to some extent):

  • Treatment of arrays (other or new shells possibly provide more convenient array handling…?)
  • Simple math computation (recent shells possibly support simple floating-point maths…?)
  • Other features useful for data handling…?
  • Shared history among different terminals
  • etc, etc

I sometimes see fish on the net, but is it possibly more suited for interactive use rather than job scripts? (FWIW, it’s totally OK for me to use shell A for interactive use and shell B for job scripts, if they have different strengths. For example, bash may be de fact standard for job scripts, so I may focus only on interactive use.)

As always, thanks very much in advance for your information!

Not really a Fortran question; most of the shells have active support groups to answer some of the questions. Most HPC systems use bash as their default. Typically programs are not written in the shell, so most shells will suffice. zsh has floating-point support and optional math functions. ksh is actually the best for floating-point opts and higher level data operations but there are licensing and availability issues there so I would not generally recommend it as something you should expect to be on platforms you do not administer (talking ksh93, not ksh88). If doing any significant computations with interpreted languages people generally use python/julia/java/ruby/awk/perl/ and not the normal interactive shells (bash,tcsh,zsh,fish, …). So unless you have control of the machine software stack I would not go to far off the beaten path without a specific goal that makes a compelling case for other shells, and do numeric computation with Fortran, and C/C++ if you have too.
I mostly write scripts in Fortran using fpm and fpm packages like M_system and M_path and M_CLI2 so I might be a bit biased, though :smile: But seriously, this is more a question for a general HPC forum or a shell forum, unless there is something you left out that ties this into the Fortran language specifically.

1 Like

I fully agree that my post is not really a Fortran question! (so the tag in the title “OT” = off-topic…). (FWIW, sometime ago I asked moderators before whether it is OK to post OT questions, and the reply was something like "it’s OK if it is related to technical / numerical topics etc.)

And thanks very much for your information! I did not know that Zsh has floating-point and math functions… (which seems definitely interesting to try).

If doing any significant computations with interpreted languages people generally use python/julia/java/ruby/awk/perl/ and not the normal interactive shells (bash,tcsh,zsh,fish, …).

I really agree with this. I use Python scripts for more complicated calculations (from data generated by Fortran), but I also write many short Bash scripts as a sort of driver, in which I often want some floating-point or math stuff (mainly for filename handling). As a result, I often end up using a mixed bash / one-liner python / awk / etc, which is rather ugly & unreadable… (in the below case I use int() for some consistency check of namelist input).
temp_inp=$( grep '^par%temp_inp ' ${wkdir}/inp | awk '{ print int($3) }' )
So, some more floating-point and math supports are already helpful in this sense.

There are several issues involved in the answers here. Various criteria might be capabilities (e.g. functions, aliases, etc.), efficiency, large file support, portability, and so on. I stopped using tcsh/csh about 20 years ago because it did not support files larger than 4GB while other shells such as bash did. If you expect your scripts to be portable and used for a long time, you might want to stick to a POSIX shell like sh. I have sh scripts that I still use that date back almost 40 years. I used perl scripts a lot starting in the late 1990s, but I was often frustrated when new versions no longer supported my scripts; also the location was not portable, sometimes being /usr/bin/perl and other times being /usr/local/bin/perl.

1 Like

I did not know that tcsh/csh are limited to 4 GB (which seems 32-bit limitation)…

I agree that portability is important. I don’t want my scripts to become invalid in a few years, but if possible, I also would like to write those shell scripts a little more straightforwardly, because I need to mix various things in one script to achieve a relatively simple thing… (though it might be the original “spirit” of Unix). One thing I am still very awkward is the array feature in Bash; to use them, I need to check a cheat sheet every time… (because I quickly forget the syntax :sweat_smile:) I wish array syntaxes were as intuitive as those in Fortran.

Though I use both Python and bash scripts for different cases, another strategy might be to stick to Python as much as possible, and use the functionality of the os module etc for file handling. Then I can fully utilize floating-points, math, and all containers in Python. But I haven’t tried this approach yet (because shell scripts are so easy for OS and file things…)

Although still not as good as Fortran or Matlab zsh array syntax is more consistent and slightly more intuitive than bash, which might be another reason to give it a look.

An example of zsh extensions to the POSIX shell
related to floating point math and arrays

#!/bin/zsh
# create an array
nums=(1.1 2.2 3.3 
      4.4 5.5 6.6)

# step through elements
for value in $nums
do
   echo $((value**2))
done

# add standard functions
zmodload zsh/mathfunc

print $(( sqrt(10.3) * cos(nums[3]) ))

# add custom function
zmath_cube() { (( $1 * $1 * $1 )) }
functions -M cube 1 1 zmath_cube

print $(( cube(3.5) ))

# list custom functions by name
print -l ${(ok)functions}

# list custom functions 
functions

# list functions in standard module
zmodload -l -F zsh/mathfunc | xargs -n 5|column -t

float A B C D
let A=100
let B='sqrt(A)'
let C='10**3'
let D=A+B+C
print $A $B $C $D

output

1.2100000000000002
4.8400000000000007
10.889999999999999
19.360000000000003
30.25
43.559999999999995
-3.1691793651648097
42.875
zmath_cube
zmath_cube () {
	(( $1 * $1 * $1 ))
}
+f:abs     +f:acos   +f:acosh  +f:asin    +f:asinh
+f:atan    +f:atanh  +f:cbrt   +f:ceil    +f:copysign
+f:cos     +f:cosh   +f:erf    +f:erfc    +f:exp
+f:expm1   +f:fabs   +f:float  +f:floor   +f:fmod
+f:gamma   +f:hypot  +f:ilogb  +f:int     +f:j0
+f:j1      +f:jn     +f:ldexp  +f:lgamma  +f:log
+f:log10   +f:log1p  +f:log2   +f:logb    +f:nextafter
+f:rand48  +f:rint   +f:scalb  +f:sin     +f:sinh
+f:sqrt    +f:tan    +f:tanh   +f:y0      +f:y1
+f:yn                                     
1.000000000e+02 1.000000000e+01 1.000000000e+03 1.110000000e+03
1 Like

I use GitHub - prefix-dev/shell: The ultimate cross-platform, bash-like shell, which works on Windows just like on Linux/macOS, but it runs natively (no emulation) and that’s amazing. All other Bash shells provide a weird path emulation layer on top. I recently started using it on macOS as my default shell also.

You also need a good terminal emulator, I started recently using https://ghostty.org/ and it works great. If they ever add a Windows port, then I’ll be all set: the same terminal and shell on all platforms.

1 Like

I’m biased towards bash. Back in the mid-1980s, my manager wanted to get a group of us familiar with unix. He discovered that Steve Bourne was going to be teaching a class near our office, and figured that might be as good a start as anything. So signed us all up for it… I still have the book and notes that Bourne provided for the class.

1 Like