Lurker News

Comments (173) 27 threads

Earlier comments
jcul1 reply#
Reminds me of the "self consuming script pattern". Seen in this super user answer.

https://superuser.com/a/440059
It embeds an awk (or any interpreter) script, and uses sed to cut out the script between tags in $0.
I agree with other comments that this kind of thing can get messy, but sometimes it makes a lot of sense and let's you share a single file.

jordemort2 replies#
The upgrade files for a product I used to work on was (and perhaps still is) a .tar.gz file with a shell script prepended to them, to make a self-extracting/self-executing archive. The archive wasn't even base64 encoded or anything; just binary data with some text in front that can find the beginning of the binary.
chriswarbo#
For those wanting to go down the self-extracting executable route, I recommend arx (it generates that sort of tarball-prepended-with-shell-script you describe) https://github.com/solidsnack/arx

The `nix bundle` command can generate an arx file, which includes all of an application's dependencies. As an example, we started getting issues with an EC2 server whose image was an accumulation of changes over several years; whilst we worked on migrating to a saner setup (containers defined using Nix), as a stop-gap we got the server working again by using `nix bundle` to create an arx executable containing working versions of all the application's dependencies, which we could copy to the existing server as a drop-in replacement of the existing (broken) command.

jcul#
Oh yeah, true, I've seen this pattern very often. Can be annoying sometimes when you just want to extract the files rather than run an installer script and they don't give an option.
forrestthewoods2 replies#
Can someone explain what this is and what it does? I have no idea. I use Windows and have never needed to use Docker for anything.
BossingAround1 reply#
It turns a Dockerfile into an executable script, so that by executing the Dockerfile, the shebang invokes docker to build and run the file.

Pretty neat if you're using Dockerfiles, but also highly non-standard so you wouldn't use it in your company repo (unless you want to increase the "what-the-fuck" level of your repo).
It's more of a "look, this is cool" kind of a thing if you're a Linux and container user.

amne#
I can see this used to install dependencies (php composer?) to inspect code with references that resolve instead of having to spinup a whole toolchain just for that
maronato#
It’s a Docker shebang. Normally shebangs are used to define what shell to use when running a script, or in the case of a python script, to run it with “./myscript” instead of “python myscript.py”.

Here OP created a little hack for building and running a docker container by adding a shebang to a Dockerfile.
Usually it’s a two step process. You first use “docker build” to build the image and then “docker run” to create a container from it. With this little hack you just run “./Dockerfile” and it does both.
It’s cool, but not really useful for most people.

rekado#
There's also `guix shell` which can be used in shebang position. Example from the Guix manual:

    #!/usr/bin/env -S guix shell python python-numpy -- python3
    import numpy
    print("This is numpy", numpy.version.version)

It also works with manifest files specifying more complex environments.
Kab1r3 replies#
This isn't POSIX compliant is it? I feel like I tried to do something different but trying to put arguments in a shebang and ran into trouble there a year or two ago.
cpuguy83#
It depends on the version of /usr/bin/env.
error9348#
Should be fine, you can even compile and run a C file using a shebang
cerved#
I believe it's compliant but only in the sense that the end result is unspecified by POSIX.

I.e. you can't rely on this working on a POSIX compliant system

Load more comments