help-bash
[Top][All Lists]
Advanced

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

Re: Can "${x##*/}" be used to replace "$(basename "$x")"?


From: Eric Blake
Subject: Re: Can "${x##*/}" be used to replace "$(basename "$x")"?
Date: Mon, 17 Feb 2020 05:40:15 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

On 2/16/20 7:33 AM, Peng Yu wrote:
Hi,

I think that "${x##*/}" is the same as "$(basename "$x")". But I am
not sure if there is a corner case that they are not the same. Does
anybody know if they are exactly the same semantically? Thanks.

They are similar, but not identical. Mike already pointed out x='/', you also encounter a difference with x='--'. The former has to be special-cased, the latter you can work around with "$(basename -- "$x").

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




reply via email to

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