You can put your shell history in a git repository (true, this is not the same thing as putting a single script file).
You can use an editor to edit command-line, e.g. C-x C-e.
You can use something like M-x shell in Emacs, then later on save the whole session in a file (in a git repo) to document things, it even shows you the evolution of building up a working one-liner *with* the outputs.
You can put your good one-liners in a script later (just chuck it in a file and prefix it with #!/bin/bash, for example).
That it actually produces a list and then the last element of the list is produced is an implementation detail.
]]>