On 03/13/2012 09:47 AM, dethrophes wrote: > Am 13.03.2012 16:42, schrieb Eric Blake: >> On 03/13/2012 09:27 AM, Eric Blake wrote: >>> 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 >> Actually, shortening /// to / is okay (it's only // that must not >> unconditionally be shortened to /, due to POSIX specification and Cygwin >> behavior of //), so a modified version would be: >> >> case $HOME in >> *[^/]* ) HOME=${HOME%${HOME##*[^/]}} ;; >> / | // ) ;; >> *) HOME=/ ;; >> esac >> > wouldn't this be better? > > case "$HOME" in > / | // ) ;; > * ) HOME="${HOME%${HOME##*[^/]}}" ;; > esac
Nope, because that strips /// into the empty string, but you really want it collapsed into the single slash. Also, I intentionally omitted the redundant "" around the variable assignment. -- Eric Blake ebl...@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature