[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Best way to remove trailing '/' from a path?
From: |
Eric Blake |
Subject: |
Re: [Help-bash] Best way to remove trailing '/' from a path? |
Date: |
Mon, 20 Apr 2015 14:58:22 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
On 04/20/2015 02:20 PM, Stephane Chazelas wrote:
> 2015-04-10 22:11:37 -0500, Peng Yu:
>> Hi, ${VAR%%+(/)} has been suggested here. But it is not robust if $VAR
>> is just a bunch of slashes. Does anybody have a robust yet succinct
>> implementation? Thanks.
>>
>> http://stackoverflow.com/questions/9018723/what-is-the-simplest-way-to-remove-trailing-slashes-from-each-parameter
> [...]
>
> Try:
>
> dirname -- "$VAR/."
Won't work on systems where // is a special root. There, 'dirname --
//' correctly outputs '//', but if $VAR is //, your line would output
'/'; similarly, if $VAR is /, your line would output '//'.
And I'm half wondering if the original poster is trying to
(re-)implement dirname without forking.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
Re: [Help-bash] Best way to remove trailing '/' from a path?, Stephane Chazelas, 2015/04/20
- Re: [Help-bash] Best way to remove trailing '/' from a path?,
Eric Blake <=
Re: [Help-bash] Best way to remove trailing '/' from a path?, Stephane Chazelas, 2015/04/20
Re: [Help-bash] Best way to remove trailing '/' from a path?, Chris F.A. Johnson, 2015/04/20
Re: [Help-bash] Best way to remove trailing '/' from a path?, Eric Blake, 2015/04/21