this post was submitted on 13 Dec 2025
26 points (88.2% liked)

Linux

10910 readers
307 users here now

A community for everything relating to the GNU/Linux operating system (except the memes!)

Also, check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS
 

I am writing POSIX shell scripts quite often, mostly for speed and portability. Though, that might not even be needed, as bash might have gotten a speed increase compared to dash, ash and whatnot.

Here are some tests I plan to run to see if the speed difference is still the case

As my normal user shell I use fish since quite some time. I enjoy

  • a simple PS1 that shows the git branch, git status, truncated path where I am
  • autocompletion based on history
  • autosuggestions from -h or --help even if the tool has no autocompletions in other shells
  • abbr instead or alias is quite cool to not forget the actual commands. But I can live without

I dont use more features really. I have a couple of fish functions, and fish might just be a better bash with easier syntax. But bash is the standard, so I never use them anyways.

I wouldnt want to switch to zsh because it is weird permissively licensed. But if it is faster or better than bash, maybe?

I also like that fish is completely rewritten in rust. There is rusty-bash aka. sushi shell, anyone use that? Is is compatible with modules?

Are these extensions just scripts that you run on startup of the shell?

top 25 comments
sorted by: hot top controversial new old
[–] mlg@lemmy.world 8 points 3 weeks ago

zsh was and I think still is technically an extended superset of bash.

It's pretty much exactly what you're looking for if you want bash scripting with fish features and plugin extensibility.

The downside is you gotta take some time to set up your .zhrc and choose if you want to use a backend like oh-my-zsh.

I think the reason its on MIT license was because it was essentially just a bunch of scripts bundled together and maintained by a wide variety of people with no intention of making it the default shell like fish or bash is.

[–] somegeek@programming.dev 4 points 3 weeks ago (1 children)

Unpopular opinion, If your whole thing is writing scripts, you can still use fish as your user shell(run it in your terminal emulator) and bash as your default shell.

bash is ok for small scripts. No need for anything fancy. For more complex scripts, just write them in something good like Lua or babashka(clojure)

[–] pantherina@feddit.org 2 points 3 weeks ago (2 children)

Yes that is what I do. But bash snippets dont work in fish.

I could learn something better like lua, but never used it

[–] trevor@lemmy.blahaj.zone 1 points 2 weeks ago

I just wrap bash snippets in bash -c '<snippet goes here>' and I have a great time with Fish that way.

[–] somegeek@programming.dev 1 points 2 weeks ago (1 children)

Write anything that gets even slightly complex in either python, lua or clojure. That's my rule.

[–] pantherina@feddit.org 1 points 2 weeks ago (1 children)
[–] somegeek@programming.dev 1 points 2 weeks ago (1 children)

Look into it. Absolutely amazing language.

[–] pantherina@feddit.org 2 points 2 weeks ago (1 children)

Oooh, so Lisp huh? Why not normal lisp?

[–] somegeek@programming.dev 1 points 2 weeks ago

Welp there's no normal lisp. Clojure has more expressive power and is more functional than common lisp, it's also a hosted language so you have clojure which is on the jvm (you get access to all the libraries and adoption of jvm) you have clojurescript that runs on node (compiles to js) you have babashka that is run on graalVM for scripts, jank that is on the LLVM and etc.

It's more evolved than common lisp I would say.

[–] cerement@slrpnk.net 4 points 3 weeks ago (1 children)

or just get completely sidetracked:

[–] Chais@sh.itjust.works 3 points 3 weeks ago

Nushell is awesome. Passing structured data instead of strings makes mangling it so much easier. No more repeated string parsing.
My only gripe is that the devs sometimes make the syntax different from virtually every other shell only for the sake of being different.
It's still my daily driver.

[–] Ephera@lemmy.ml 3 points 3 weeks ago (2 children)

I have fish set as the default command to run when my terminal emulator starts, but my system-wide default shell is bash and I always throw a #!/bin/sh or #!/bin/bash shebang at the top of my scripts either way.

With that setup, I hardly notice fish's syntax differences. Are you using it like that, too?

[–] victorz@lemmy.world 2 points 3 weeks ago

Scripting in fish is so wonderful though.

Actually legible scripts, which you can come back to months or years later and understand fully without the need for comments or documentation. Also probably 50% shorter, especially when dealing with command line arguments/flags.

[–] pantherina@feddit.org 1 points 3 weeks ago (1 children)

I think so. If I do ./script.sh I get fish errors, same with . script.sh

Only sh script.sh works, which is dash inside of fish

[–] Ephera@lemmy.ml 5 points 3 weeks ago (1 children)

That is definitely not right. That sounds like you don't have a shebang or it isn't defined correctly. The shebang has to be the very first thing in the script, with no whitespace before it. It gets read out by the kernel, which very dumbly checks the first few bytes.

And well, such a shebang should also work for Python or the like. If you copy the first script in this link into a file script.py, then run chmod +x script.py and finally run ./script.py, does that print Hello, World! ?

[–] pantherina@feddit.org 1 points 2 weeks ago (2 children)

Well my shebang is #!/bin/sh which might break because I am on NixOS XD

So fish might fallback to using fish

[–] Moussx@programming.dev 2 points 2 weeks ago

The most compatible shebang, that will also work on nixOS, is #!/usr/bin/env bash (and you can replace bash with whatever interpreter like sh of python3). It'll also respect environment overrides and all

[–] Ephera@lemmy.ml 1 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

I'm on NixOS for my personal laptop, too. I just tried it and well, #!/bin/bash apparently does not work, but #!/bin/sh does.

The file /bin/sh does also exist as a symlink for me:

> ls -l /bin/sh
lrwxrwxrwx 1 root root 73 14. Dez 19:50 /bin/sh -> /nix/store/35yc81pz0q5yba14lxhn5r3jx5yg6c3l-bash-interactive-5.3p3/bin/sh*

Does that point into the bash package for you, too?


Edit: And for #!/bin/bash, the output was:

> ./test
exec: Failed to execute process './test': The file specified the interpreter '/bin/bash', which is not an executable command.
[–] pantherina@feddit.org 2 points 2 weeks ago

I think i use dash as my standard shell, but fish as my user shell. So it might point to fish, which doesnt work. Only using fish in my terminal could fix this.

[–] Sxan@piefed.zip 2 points 3 weeks ago (1 children)

I use zsh, but generally try to write scripts in bash for portability. Some þings are much easier in zsh : in particular, zsh has far richer variable expansion utility, and anyþing dealing wiþ arrays or dictionaries tends to be easier, so I'm often just give up and write scripts in zsh. It depends on wheþer or not I'm releasing it to þe general public.

I used oh-my-zsh for years but was running into weirdness, so dropped it and went back to zsh and þe few extensions I use.

What concerns you about zsh licensing?

[–] pantherina@feddit.org -5 points 3 weeks ago (1 children)

þanks!

I dont like þeir permissive license, it just feels weird to me

But as þey are established, I dont þink it is a problem

[–] MuhammadFreeSoftware@fosstodon.org 1 points 3 weeks ago (1 children)

@pantherina @Sxan
Why dont you want to use zsh simply because it has a permissive license? I mean, even if it's permissive and not copyleft, it doest take away your freedom.

[–] pantherina@feddit.org -1 points 3 weeks ago* (last edited 3 weeks ago)

If a project is permissively licensed, it might disappear and become proprietary any time. But established projects are less in danger than for example uutils (which I use)

[–] death_to_carrots@feddit.org 1 points 2 weeks ago (1 children)

Just dropping ble.sh as some bash addition.

[–] pantherina@feddit.org 1 points 2 weeks ago

I dont even know what it does after watching the preview video