Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@loxaxs
Created February 6, 2019 06:51
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 loxaxs/7cbe84aed1c38cf18f70d8427bed1efa to your computer and use it in GitHub Desktop.
Save loxaxs/7cbe84aed1c38cf18f70d8427bed1efa to your computer and use it in GitHub Desktop.
Multiple arguments in shebang
#!/bin/bash
#
# /usr/local/bin/run
#
# Split the first argument on IFS and replace bash by running the resulting command.
# Shebang to this script to be able to use multiple arguments in your shebang.
# Usage (at the beginning of a file):
# #!/usr/local/bin/run python3 -O -i
# print("__debug__ :: {}".format(__debug__))
# How (why) does it work ?
# Say you have a file, named `my_runnable`, which contains the text in the Usage section above.
# If you run:
# `./my_runnable argA argB`
# Then, during the execution of `/usr/local/bin/run`, we'll have:
# $1: "python3 -O -i"
# $2: "argA"
# $3: "argB"
#
# Doing `$first "$@"` in the final command will split `$first` on characters specified in IFS.
IFS=' '
first="$1"
shift;
exec $first "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment