Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active September 22, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/bf6d6c6376f0bc6db38d915e94cbc543 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/bf6d6c6376f0bc6db38d915e94cbc543 to your computer and use it in GitHub Desktop.
Run C Interpreted Scripts #c

Run C Interpreted Scripts

Derived from: https://news.ycombinator.com/item?id=9145279

Just put this on the first line of your C file:

//usr/bin/env make -s "${0%.*}" && ./"${0%.*}" "$@"; s=$?; rm ./"${0%.*}"; exit $s

Then just do chmod u+x ./main.c; ./main.c.

Make sure there isn't a directory that has the same name as your C file name, otherwise it won't work.

If you can combine this with nix-shell shebang you might even get a package manager for free too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment