Table of Contents for Programming Languages: a survey
Shell
Best practices and style guides:
Bash Shell
Best practices and style guides:
Tutorials:
Gotchas:
Best practices:
Frameworks:
Notes:
Powershell
https://msdn.microsoft.com/powershell
"abstracting gorp into high level task oriented abstractions, object pipelines, structured data, and the workflow from interactive shells to ad hoc scripts to formal scripts to production scripting." -- a powershell designer
Features:
- pipe strongly-typed objects
Tutorials:
Retrospectives:
Opinions:
- "Once you've piped strongly-typed objects around between your shell commands, text scraping seems barbaric by comparison" [2]
- bad implicit returns [3]
- "...Powershell allows calling into COM, .NET or straight DLLs for that matter. It is also what I see as missing opportunity in most UNIX shells that failed to build up on Xerox PARC, Lisp Machines and ETHZ experiments. The ability to directly plug into shared libraries, UNIX IPC, and modern mechanisms like DBUS and gRPC, alongside live debugging capabilities, thus exposing the whole OS stack to the CLI, making it a proper REPL experience. Other than that, it looks quite cool." -- https://news.ycombinator.com/item?id=24079520
- "...everything you can do in VB6 you can do in powershell, and do it better. Try/Catch, windows forms..." [4]
- "Quickly and easily design and make a GUI program with n real training? VB6 got me into programming as a kid. I mostly use python for stats stuff. I sorta understand how to run up a GUI using tkinter, but it seems like a huge pain... VS isn't intuitive - it's a firehouse of information and I feel like you need training to use it. That is a bummer." [5]
- "HyperCard? occupies the same spot for me that VB6 seems to occupy for you. Today for stuff I'd have used that for in the 90s, I just stand up a quick little web app and text or email a link...Unless I want to throw my cute GUI in an app store, it needs to be web-based now." [6]
- "Powershell as language is pretty bad" [7]
- "Yeah, I write a ferocious amount of PowerShell? it's an amazingly bad language. I use it for its API, but its language design is a nightmare." [8]
- " I don't find it ugly, just strange. It's optimized for interactive usage though from what I understand. I think of it mostly as calling .NET methods that all have named parameters: myfunc -param1 this -param2 that instead of: myfunc(param1: this, param2: that); I get the impression it's designed with the intent that you're supposed to type the dash, then hit Tab to get tab-completion in most cases. Same with the verb/noun syntax (I know I want to 'Get' something, so typing Get-<Tab> for the list of things is usually the thing to do). I do find it a bit difficult sometimes to think of an approprioate verb right off the top of my head (is it Get- or New- that I need?). I'd also love to see the concept of proper namespaces in PowerShell?; it seems really inconsistent right now (unless I've missed something). For example, type Show-Command and hit ENTER, then look at the different modules that are available. Some will express a 'namespace' by having it prepended to the noun (see for example, commands from the BitLocker? module, their nouns all start with BitLocker?) while others express no namespace at all (see for example commands from the 'Dism' module). For everyday use I've gone with the 'add the name to the noun' approach in my own scripts. That does mean I tend to use short namespace names though. I've mentioned this in an older PowerShell?-related thread here - MenuComplete? is absolutely awesome and improves the PowerShell? experience in the console. I actually think it should be the default. If you havent already, try these commands: Set-PSReadLineKeyHandler? -key Tab -Function MenuComplete? Set-PSReadLineOption? -ShowToolTips? PowerShell? is my full-time shell in Windows now (and it will be in Linux also when I get back into it); I rarely use CMD for anything and parsing text in bash just seems antiquated. " [9]
- " Take the following in PowerShell?: ls
sort DateTime? -d |
ls returns an array of objects, sort then sorts the array by each object’s DateTime? field (and here I’m asking it to sort in descending order with -d). The point is that sort isn’t depending on any text output, so it works with any array of objects regardless of the command that returned them. The other cool thing this enables is auto-complete awareness in the shell. If I typed: ls sort <Tab> |
then the shell knows what makes sense in auto-completion here as ls has an actual return type and in this case it will give me a list of available fields that I can sort on. For those unfamiliar: ls and sort here are shortened aliases to more wordy verb-noun commands. These (as well as a large bunch of others) are given to you by default. " [10] " Yeah, PowerShell? is the only mainstream shell that behaves like the REPL environments from Xerox PARC workstations. Structured data with direct access to any OS API, regardless how it is provided, .NET, COM or straight C like DLL. UNIX world never had that, beyond trying to fit language repls as user shell, which on UNIX always feels like a leaky abstraction. " [11]
- "The cmdlets are super useful but the language is just really weird." [12]
- "I'm more fluent with bash, but that's only because I used bash a lot. PowerShell? feels more robust, no silly space-in-filename problems, no silly parsing of text output to access fields. May be it's ugly for big scripts, I don't know, for me it looked like a vastly superior version of shell." [13]
- "between the awkward wait for it to boot, the stupid naming convention, and the knowledge that the whole power of the .net framework should be at my finger tips, but in a really alien and unintuitive way, I prefer to either write a really small bat, or write a small C# console app...I just wish they'd admit defeat and just use a subset of C# instead of stubbornly sticking with something that seems fairly widely loathed." [14]
- "One criticism I've seen and levied myself is the sheer amount of typing: [PS] C:\> Get-MyReallyLongFunctionName? -Server furtle $ lol --floop PS is fine but it takes ages for the bloody thing to wake up and notice command completion. It is like dealing with a teenager in bed. Actually, I have no problems with PS but with MS's idea of search as deployed to users. " [15]
- "Verb-first was also a bad choice. When I type “get” I am getting thousands of suggestions which makes autocompletion pretty useless. There is also no way to find all cmdlets that deal with active directory. It would be much better if I could type “AD” first and then get all cmdlets that deal with active directory. " [16]
- "I just found it un-intuitive, ugly, and verbose. Compared to my beloved python it looks really really bad. " [17] Code:
- https://github.com/PowerShell/PowerShell
- https://stackoverflow.com/questions/3637668/why-are-scripting-languages-e-g-perl-python-and-ruby-not-suitable-as-shell/3640403#3640403
- https://buttondown.email/hillelwayne/archive/i-really-like-powershell/
Scheme shell
Turtle shell (Haskell)
Zsh
Tcl
not exactly a shell language, but i'm putting it in this chapter
Opinions:
- "... I recently discovered that with tclreadline, Tcl can be used completely in place of Bash in interactive mode, in a way that something like Python absolutely cannot. A lot of people seem to have negative opinions about Tcl (maybe because it's more of a LISP than its syntax seems to imply), but as someone who is just discovering it, I'm shocked at how powerful it is for how unpopular it seems to have become. It's like some kind of unexpected cross between Bash, LISP, and (with Tk) Visual Basic. There's something about it that's just kind of fun. " -- [18]
- "Tcl is awesome. I used it constantly in the 1990s. It's outstanding for things like testing and build scripts. I think some of the pushback might be because people tried to use it to build large applications and failed. Languages like Java and (dare I say it) Visual Basic were more comprehensive and had good IDE support. " -- [19]
- "...Tcl's flexible, to the degree of being able to define new language constructs or redefine built-ins (e.g. you can redefine the basic if-then if you want), which is great in some ways..." [20]
- "...it looks like shell commands: blah blah blah. As opposed to blah("blah","blah"). And this, folks, is what I think Tcl, being a tool command language, gets right... Tcl likes literals, not variables. Tcl: string, $var. Pop infix: "string", var. Tcl likes commands, not expressions. Tcl: doit this that, [expr $this+$that]. Pop infix: doit("this","that"), this+that. ...flat function calls with literal arguments is what interactive program usage is all about.. Short code matters a lot; short interactive commands matter much more. An interactive command language must be a real language (loops, functions and all). Tcl allows for the shortest commands and it's a real language. I'm fascinated. ...the shell is an insanely defective programming language, so it's not even an option for anything non-interactive. But Tcl gets way closer to a programming language. " -- https://yosefk.com/blog/i-cant-believe-im-praising-tcl.html
- https://wiki.tcl-lang.org/page/Advantages+of+Tcl+over+Lisp
Tutorials:
Variants and implementations:
Links:
Fish shell
https://fishshell.com/
Opinions:
- "...It has some serious limitations as a scripting language, namely lack of proper subshell support and background process control. The relevant issues have been open for years with no clear resolution in sight. (which is fair, these are very hard problems and it's an open-source project with finite resources) That's fine though, it's still my favorite interactive shell for use in a Terminal. I just make sure to write any script longer than a few lines in Bash..." -- [21]
- "The best part about fish is you don't have to configure it much to be productive in it." -- [22]
- "> It seems that shell scripting languages tend to be quite ugly out of necessity?... It isn't inevitable by any means, fish shell scripting is clean and pleasant." [23]
Oil shell
https://www.oilshell.org
https://news.ycombinator.com/item?id=24083931
http://www.oilshell.org/why.html
https://github.com/oilshell/oil/tree/master/doc
https://github.com/oilshell/oil/blob/master/doc/idioms.md
https://www.oilshell.org/blog/2019/10/04.html
http://www.oilshell.org/blog/2020/01/simplest-explanation.html
http://www.oilshell.org/preview/doc/syntactic-concepts.html
http://www.oilshell.org/preview/doc/syntax-feelings.html
" Command vs. Expression Mode
This is an essential syntactic concept. An Oil program starts in command mode, and commands are composed of words:
echo "hello $name" ls
However there are several keywords and sigils that put you in expression mode, e.g. so that * means multiplication rather than glob:
var x = 1 + 2*3 + f(x) # After =, you're in expression mode
myfunc(42, 'foo') # Pretty-prints the result, without assigning
Inline calls also put you in expression mode:
echo $strfunc(1 + 2*3) # Between (), you're in expression mode echo @arrayfunc(x, y)
There are also expression substitutions with $[expr]:
echo "attr = $[obj.attr]" echo "key = $[d->key]" echo "item = $[array[1 + 2*3]]" " -- https://www.oilshell.org/blog/2019/10/04.html
" So the Oil language is just one part of the project, but it can also be broken down into many features! I drafted a blog post on Zulip to explain this, and I mentioned it in the long Nix RFC thread to give Nix users a sense of the project.
In the draft, I broke down the language into 5 major features, and gave an estimate of how done each one is:
Python-like expressions on typed data: 9/10. This could be 7/10 or 8 /10 because we still need to divorce the expression evaluator from Python.
Eggex (regular expression syntax): 9/10
Procs: 6/10 (could be 7/10 after recent progress; we need to finish typed arguments)
Ruby-like blocks for DSLs: 3/10. Need eval (myblock), etc.
QTT (TSV-like tables): 3/10. We emit QTT in one place: pp proc, but we don't have a parser. The building block QSN is done!
This is still correct, although we should add more space for:
Pure functions, and a unique form of coprocess: 2/10
Shell builtins, which are like a "standard library": 4/10
argparse for flag parsing
describe for a test framework
I also mentioned the Awk and and dplyr-inspired builtins in the last post.
" -- [24]
Nushell
http://www.jonathanturner.org/2019/08/introducing-nushell.html
https://dataswamp.org/~solene/2022-10-31-nushell.html
opinions:
- " I just ported a bunch of scripts to nushell. I hit some bugs, a couple of which are a bit sharp, but wow, the list of quirks I have to remember for nutshell are so much fewer than for bash. Constantly impressed at the errors it catches at parse time, kinda crazy sometimes. Oh my god I could cry, strings are sane to work with. I may never write a bash script again (it's okay, I use Nix so I get nushell everywhere I'm might need it, for free) Everyone is asking about PowerShell?. I never hated it, but lord it makes some awful, stupid infuriating decisions. I've lost hair and sanity to some stupid list/single-item-list beahvior. Numerous operators and bits of syntax are just different. Everything about the script syntax is just slight odd and confusing. There's basically none of this with nushell. Jonathan Turner is a gifted person with an eye for language design and it really shows. Edit: I do think it's missing some important output redirection functionality. You can workaround by using "complete" but that feels non-ideal. " -- [25]
Crush
https://github.com/liljencrantz/crush
"The author, Axel Liljencrantz, was also the initial developer of fish..." -- Robin Reala
elvish
uxy
Marcel
Xonsh
http://xon.sh/
Python-powered shell
Rash
Racket shell
tools to use other languages in shell pipelines
jc and jq
(not a shell, but a related idea)
"I believe a good fit for Unix commands is using a pipeline where the output of your command (say, ls) is converted to JSON, so that later in the pipeline you can use jq to filter / count / etc in a structured, non-whitespace-dependent way. A combination of jc (https://github.com/kellyjonbrazil/jc) and jq fits the bill for me:
ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)'" -- https://news.ycombinator.com/item?id=24080057
Babashka
(not a shell, but a related idea)
https://github.com/borkdude/babashka
mario
https://github.com/python-mario/mario
"Mario, for Python code in shell pipelines. Its most novel feature is (optional) async commands, so you can pipe in a list of urls, make many concurrent requests, and then process them in a single line.
cat urls.txt | mario async-map 'await asks.get ! x.json()' apply len
" -- https://news.ycombinator.com/item?id=24079303
Closh
https://github.com/dundalek/closh
Oh
https://github.com/michaelmacinnis/oh https://www.youtube.com/watch?v=v1m-WEZz46U
See also Kernel
lash#Cat9 (Arcan shell)
https://arcan-fe.com/2022/10/15/whipping-up-a-new-shell-lashcat9/
Shell implementation
List of shell languages and projects