fish as a non-interactive shell / fish als nicht-interaktive Shell

in Deutsch D-A-CH2 years ago

English version below


Hallo,

ich habe vor einiger Zeit (ziemlich genau fünf Monate) für die fish-Shell für den täglichen Einsatz entschieden. Zum Teil wegen Sachen wie gut funktionierendem Syntax Highlighting, Auto-Vervollständigung, History - all das ohne extra 'was konfigurieren zu müssen. Auf diese Features will ich heute aber nicht eingehen, dafür möchte ich meine Erfahrungen mit dem eingebauten Skript-Syntax eingehen. Der verspricht nämlich, expliziter, einfacher und vorallem weniger kryptisch und mit hart zu erlernenden Sonderfällen gespickt zu sein im Vergleich zu bash.

https://fishshell.com/docs/current/language.html

https://fishshell.com/docs/current/fish_for_bash_users.html

Die wichtigen Unterschiede schienen für mich (bis jetzt):

  • Statt der eingebauten String-Ersetzungen a la ${var:etc blablabla} und ähnlicher Konstrukte gibt es die explizitere (aber natürlich von der Tipparbeit her längere) string-Direktive

  • Variablen werden mit set gesetzt: Das war die für mich wohl krasseste Veränderung und die einzige (außer vielleicht die verwandte Funktion des "Default-Wert annehmen falls Variable nicht existiert"), die für mich wirklich den Eindruck erweckt haben, dass es unnötig ausführlich ist, in fish zu scripten.

    Die Lösung für letzteres ist übrigens anscheinend, laut StackOverflow, set -q zu verwenden, etwa so: (set -q prüft, ob Variable existiert; or tut dann short circuiten). Man könnte natürlich dafür auch eine Funktion imlementieren, dies sei dem Leser als Übungsaufgabe überlassen…

set -q TEST; or set TEST 1
echo $TEST

  • Variablen werden nicht implizit an Whitespace gesplittet, was double quoting überflüssig macht. Ähnlicherweise werden auch Wörter z.B. bei der Command Substitution nur an Newlines getrennt. Das widerrum finde ich fantastisch, weil ich doch sehr oft bei bash mit Fehlern a la 'meine Eingabe enthält Leerzeichen und wird deswegen aufgeteilt, ohne dass ich das wollte oder auch irgendwie vorhergesehen hatte' konfrontiert war.

Das (und der BASIC-like Syntax vs. C-like bei bash) waren die Sachen, die mir überhaupt bei meinem Übungsbeispiel aufgefallen waren. Ich hoffe, ich finde morgen die Zeit, das Übungsskript hier auch durchzuspielen.


English version


Hello,

I decided some time ago (almost exactly five months) to use the fish shell for daily use. Partly because of things like well working syntax highlighting, auto-completion, history - all that without having to configure anything extra. But I don't want to go into these features today, instead I want to talk about my experiences with the built-in script syntax. It promises to be more explicit, simpler and above all less cryptic and riddled with hard-to-learn special cases compared to bash.

https://fishshell.com/docs/current/language.html

https://fishshell.com/docs/current/fish_for_bash_users.html

The important differences seemed to me (so far):

  • Instead of the built-in string substitutions a la ${var:etc blablabla} and similar constructs, there is the more explicit (but of course longer in terms of typing) string directive.

  • Variables are set with set: This was probably the most glaring change for me, and the only one (except perhaps the related function of "assume default value if variable does not exist") that really made it seem to me that scripting in fish is unnecessarily verbose.

    By the way, the solution to the latter, according to StackOverflow, is apparently to use set -q, something like this: (set -q checks if variable exists; or then does short circuiten). One could of course also implement a function for this, this is left to the reader as an exercise....

set -q TEST; or set TEST 1
echo $TEST

  • Variables are not implicitly split at whitespace, which makes double quoting unnecessary. Similarly, words are only split at newlines, e.g. in command substitution. I find this fantastic, because I was often confronted with errors like 'my input contains whitespace and is therefore split without my intention or even foreseeing it' when bashing.

That (and the BASIC-like syntax vs. C-like in bash) were the things I noticed at all in my exercise example. I hope I can find the time tomorrow to run through the exercise script here as well.

Sort:  

Congratulations @t-nil! You received a personal badge!

Happy Hive Birthday! You are on the Hive blockchain for 1 year!

You can view your badges on your board and compare yourself to others in the Ranking

Check out the last post from @hivebuzz:

Hive Power Up Month - Feedback from May - Day 15
Support the HiveBuzz project. Vote for our proposal!