Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Oct 2022 11:32:14 +0700
From:      Eugene Grosbein <eugen@grosbein.net>
To:        Nuno Teixeira <eduardo@freebsd.org>, FreeBSD Mailing List <freebsd-ports@freebsd.org>
Subject:   Re: sh: getting <category>/<portname> from pwd
Message-ID:  <69442eed-b2e1-5be3-39f1-aef413606fcb@grosbein.net>
In-Reply-To: <d06cd71d-bb8b-192b-d927-0314ae544a11@grosbein.net>
References:  <CAFDf7UJp9PkrhfMmJRKO7QNTmGQYu7BQYyqczoz-Dy7hP3h74g@mail.gmail.com> <d06cd71d-bb8b-192b-d927-0314ae544a11@grosbein.net>

next in thread | previous in thread | raw e-mail | index | archive | help
26.10.2022 11:31, Eugene Grosbein wrote:

> 26.10.2022 5:14, Nuno Teixeira wrote:
>> Hello all,
>>
>> I'm writing a shell script to feed poudriere testports and I need to get <category>/<portname> from ports tree:
>>
>> `pwd`:
>> /home/user/work/freebsd/ports/<category>/<portname>
>>
>> `pwd | rev | cut -d / -f1,2 | rev` do the trick but it is so uggly!
>>
>> Is there a shell option to get it?
> 
> Naturally, there is.
> 
> cwd=$(pwd)
> echo ${cd##*/ports/}

echo ${cwd##*/ports/}

> This is documented in sh(1) manual page, section "Parameter Expansion".
> No need to call external tools.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69442eed-b2e1-5be3-39f1-aef413606fcb>