Skip to content

Comment on Scriptisto: "Shebang interpreter" that enables writing scripts in compiled langs

Comments

Somewhat related: nix-shell supports an additional shebang, allowing summoning of any combination of packages, to be made available inside a script. An example from the docs[1]:

  #!/usr/bin/env nix-shell
  #![allow()] /*
  #!nix-shell -i bash -p rustc
  rsfile="$(readlink -f $0)"
  binfile="/tmp/$(basename "$rsfile").bin"
  rustc "$rsfile" -o "$binfile" --edition=2021 && exec "$binfile" $@ || exit $?
  */
  fn main() {
      for argument in std::env::args().skip(1) {
          println!("{}", argument);
      };
      println!("{}", std::env::var("HOME").expect(""));
  }
and another:
  #! /usr/bin/env nix-shell
  #! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [turtle])" -i runghc

  {-# LANGUAGE OverloadedStrings #-}

  import Turtle

  main = echo "Hello world!"

1. https://nixos.wiki/wiki/Nix-shell_shebang
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.