Say I have a file hello:
#!/bin/sh
echo "Hello World!"
Provided the executable bit is set on that file, I can execute it by entering its path on the prompt:
$ ./hello
Hello World!
Is there a more explicit equivalent to the above? Something akin to:
$ execute hello
I know I can pass hello as an argument to /bin/sh
, but I'm looking for a solution that automatically uses the interpreter specified in the shebang line
My use case for this is to execute script files that do not have the executable flag set. These files are stored in a git repository, so I would like to avoid setting their executable flag or having to copy them to another location first.
#!
line withINTERPRETER=$(sed -n ' /^#!/s///p;1q' "YOUR_SCRIPT")
and then"${INTERPRETER:-/bin/sh}" "YOUR_SCRIPT"
? Make a script out of it.command_not_found_handle()
feature of bash to catch commands likehello
(wherehello
is not found inPATH
), but not for./hello
orpath/to/hello
.