:: originally posted by gbussi ::
Quote:
Hello,
I am writing a bash script which I would like to be as portable as possible.
I require that bash version 2 is installed, but I DON'T want to require a fixed location for it.
The following wrapper should search bash in the current PATH and execute itself using it.
The only bug is that "bash something" first search "something" in the current directory,
and then in the current PATH. This can lead to some problem if a file with the same name
of the script itself exists in the current directory.
Any suggestion?
Any simpler way to solve this problem?
Do you know if this solution is REALLY portable on any system (a part from the bug I exposed)?
Thanks a lot!
Giovanni
#! /bin/sh
# PORTABILITY WRAPPER
# This part of the script is aimed to relaunch the script itself using a bash interpreter.
if test $# -eq 0
then
bash --noprofile --norc "$0" --this-is-bash
exit
elif test "$1" != --this-is-bash
then
bash --noprofile --norc "$0" --this-is-bash "$@"
exit
fi
shift
(( ${BASH_VERSINFO[0]} < 2 )) && { echo "$0: bash version 2 is required" ; exit 1 ; }
# END PORTABILITY WRAPPER
# The real script follows
# ...