A very (very) simple Hello World program in Haskell.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Foreign.C.Types
import qualified Language.C.Inline as C
C.include "<stdio.h>"
C.include "<stdlib.h>"
main :: IO ()
main = [C.block| void {
system("python -c 'print \"Hello, World!\"'");
} |]
Better to not announce to the world "Hey everyone! Whaddya think?" If you can only tolerate approving answers. No one made them post a bad version of a one-liner that could already be googled up from 20 other examples already out there and better engineered.
This sort of send-up is actually perfectly on target, and frankly actaully light hearted.
Everyone posting critiques like this and like my own, knows full well that they have their own excrable works of art out there. We've all been figurative 7 year olds and made terrible crayon drawing programs, and even been ignorantly and adorably proud of them at the time.
And the initial : is there to create a valid executable line where variables and brace expansions are actually evaluated, but without actually doing anything else. : is a synonym for true.
Sort of like a comment in that no statement is executed (well a statement is executed, it's just a almost-no-op statement) but unlike a comment in that the braces are evaluated, and any actions they perform like assignments, are evaluated and performed.
Most brace expansions just expand something in place, they essentially mostly just read and display something, possibly modifying it along the way from memory to output. But a few brace expansions actually do assignments. And that "set to this value if not already set to anything" is very useful. So a common trick is things like
:${DEBUG:=false}
: is just a synonym for "true" ie a valid command that does nothing but also does not produce an error and also is an executable statement not a comment.
Everything after the true is evaluated for real just like if true were instead echo or any other command.
The end result of that debug example is now all through the rest of the script you can put $DEBUG && echo doing step 7...
and never have to worry about the invalid syntax condition if DEBUG had not been set to something. All else being equal, it's always going to be set to false, and so all those debug commands will be valid syntax.
But you can enable verbose mode later at run-time without editing the script by running
DEBUG=true myscript
The := brace expansion means that since DEBUG was set to something, it's not modified, not set to false. it's only set to false if it was unset to begin with.
It's basically the shortest way to define a configurable with a default value at the same time.
Unneccessary $() fork, unnecessary cat, and at best a bit thoughtless to expand the file's contents onto a commandline just to squirt it. Sorry buddy, but, do not be proud of this.
[edit I should not simply say that without showing what is supposedly the better way]
There are several versions of nc, mine uses -N to exit on eof.
From here it's only a little more to read -n 4096 to read in 4k chunks instead of in lines, since a valid html document could actually be all on one line of arbitrary unlimited length, and the final version above would be no different from the "allow large cmdline" version.
What about a systemd socket activated service that passes the network data through stdin? They'll spawn a new bash process for every incoming connection, and technically wouldn't need nc.
Very much so! I wanted to write it in pure bash without nc but couldn't find a way straight away. The main change here is the -c which lets you drop the connection at EOF so you can have psudo-concurrent connections.