Skip to content

Instantly share code, notes, and snippets.

@thvitt
Created May 5, 2014 08:19
Show Gist options
  • Save thvitt/11531321 to your computer and use it in GitHub Desktop.
Save thvitt/11531321 to your computer and use it in GitHub Desktop.
A script that, for each argument, creates a shell script that calls `exec ‹argument› "$@"` in the current directory. Useful instead of symlinks for commands that refer to `$0` but that do not resolve symlinks.
#!/bin/sh
help() {
cat <<EOF
$0 /path/to/target/program ...
Creates a simple executable that forwards to the target program in the current
directory.
EOF
exit 255
}
createSingleForward() {
target="$1"
forward=`basename "$1"`
cat > "$forward" <<EOF
#!/bin/sh
exec "$target" "\$@"
EOF
chmod 755 "$forward"
}
if [ "$#" -lt 1 -o "$1" = "--help" -o "$1" = "-h" ]
then
help
else
while [ $# -gt 0 ]
do
createSingleForward $1
shift
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment