Skip to content

Instantly share code, notes, and snippets.

@loxaxs loxaxs/run.sh
Created Feb 6, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.