Created
February 6, 2019 06:51
-
-
Save loxaxs/7cbe84aed1c38cf18f70d8427bed1efa to your computer and use it in GitHub Desktop.
Multiple arguments in shebang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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