help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] basename for n levels


From: Peter West
Subject: Re: [Help-bash] basename for n levels
Date: Wed, 10 Jun 2015 23:51:58 +1000

Why do you need the double slashes out?

You can always pipe the first stage of output through tr -s ‘/‘.


> On 10 Jun 2015, at 11:33 pm, Peng Yu <address@hidden> wrote:
> 
> For example:
> 
> If the input string is a////b///c///d//e, and n=3, the output should be c/d/e.
> 
> If n=4, the output should be b/c/d/e.
> If n>=5, the output should be a/b/c/d/e.
> 
> If the input string is ///a////b///c///d//e, and n=3, the output
> should be c/d/e.
> 
> If n=4, the output should be b/c/d/e.
> If n=5, the output should be a/b/c/d/e.
> If n>=6, the output should be /a/b/c/d/e.
> 
> 
> On Wed, Jun 10, 2015 at 7:58 AM, Greg Wooledge <address@hidden> wrote:
>> On Wed, Jun 10, 2015 at 07:54:59AM -0500, Peng Yu wrote:
>>> On Wednesday, June 10, 2015, Dennis Williamson <address@hidden>
>>> wrote:
>>>> or you can use read and an array
>>>> 
>>>> IFS=/ read -a parts <<< "$var"
>>>> 
>>> 
>>> This is not robust wrt multiple consecutive slashes.
>> 
>> Demonstrate the failure.  Give an example input, the desired output, and
>> the actual output.
> 
> 
> 
> -- 
> Regards,
> Peng
> 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]