I have a bash shell script(my_script.sh
) which runs a script(their_script
) during execution. My script (my_script.sh
) looks like this :
THISDIR=`dirname $(readlink -f $0)`
main() {
cd $THISDIR
source their-script
}
main "$@"
their-script
is a file I should not change. their-script
has this stuff:
BDIR="$1"
...
BDIR=`readlink -f "$BDIR"
Everything above works great. I would like to add some options, so I changed my_script.sh
to look like this:
THISDIR=`dirname $(readlink -f $0)`
check_options() {
while [ "$1" != "" ]; do
case $1 in
--username ) shift
OPTIONS_USERNAME=$1
;;
* ) # No more options
;;
esac
shift
done
}
main() {
check_options
cd $THISDIR
source their-script
}
main "$@"
Now, when I run ./my_script.sh --username example
, their-script
fails during execution of:
readlink -f --username
and spits out this line:
readlink: unrecognized option '--username'
How can I prevent my script's positional parameters from breaking other scripts in this way?
readlink
?