I have the following script that I call from my .bash_profile
:
# Set directories based on current path
__set_dirs() {
currdir=`pwd`
if [[ ${currdir} =~ "\/path\/to\/main\/(.*)\/working\/([a-z]+)(/?.*)" ]]
then
ws=${BASH_REMATCH[1]}
subdirs=${BASH_REMATCH[3]}
stgdir=${ts}/${ws}/STAGING${subdirs}
else
echo "${currdir} is not a workspace"
stgdir=""
fi
}
# Update local version with staging version
upd() {
__set_dirs
if [[ -n ${stgdir} ]]
then
__overwrite=0
while getopts "o" opt
do
case $opt in
o)
__overwrite=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
echo "Updating ${currdir} with latest from ${stgdir}..."
if [ ${__overwrite} -eq 0 ]
then
update -r ${stgdir} ${currdir}
else
echo "Overwriting all local changes!"
update -r -w ${stgdir} ${currdir}
fi
fi
unset __overwrite
}
When I execute
> upd -o
The flag is completely ignored--I never see the message "Overwriting all local changes!". Have I missed something somewhere?
UPDATE: It does work, but only the first time I run the script. From the second time on, the flag gets ignored.