On 03/13/2012 09:18 AM, Roman Rakus wrote:
as a workaround to your problem you could have something like this in
your bashrc
if shopt extglob&>/dev/null ; then
HOME="${HOME/%+(\/)}" # strip all trailing forward slashes
else
while [ "${HOME}" != "${HOME%\/}" ] ; do
HOME="${HOME%\/}"
done
fi
I think it should hide your problem.
Is it all necessary?
HOME="${HOME%\/}"
That only strips one trailing slash. If you want to strip multiple
trailing slashes, then you have to go with something more complex; but
the above if/shopt/else/loop approach is overkill, compared to this
one-liner:
$ foo=/a/b///
$ echo ${foo%%/}
/a/b//
$ echo ${foo%${foo##*[^/]}}
/a/b
Be aware that both approaches will misbehave if HOME is a root directory
(/ or //), where you _don't_ want to strip trailing slashes. So you
really want:
case $HOME in
*[^/]* ) HOME=${HOME%${HOME##*[^/]}} ;;
esac