From nobody Wed Oct 26 12:14:05 2022 X-Original-To: freebsd-ports@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4My75k0KTNz4fwVg for ; Wed, 26 Oct 2022 12:14:18 +0000 (UTC) (envelope-from eduardo@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4My75j6fTSz41bm for ; Wed, 26 Oct 2022 12:14:17 +0000 (UTC) (envelope-from eduardo@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666786457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lcaS/sutoNQj8XOpq9zr6F0GNFn3d6k68EzFs5KVZio=; b=A2gfx9gkcd6ZhLdYScsAG/5LrXSc7kZaD0PnNLrAzAJ4lRIWwLZvoK8ohJcrcYS6TiX9Wh AU3BUWgRmGIitD4tZp37Y1JflOSMPg4g9faUjUTiAjRhNrCk/VNnV68KNmnyVolxHVi2pA vNZv0PGcrRQg3xBzvA6M53ntPYaWIqCZTkyTcGaYAFeuhbBv0yroPZ0kwrir7qZcgoytxD 4lRYLS4TLdZT//CfXHNtfzmz1zbwaGm8HYB2aWBx9OaudTvyHRJ/0JphWi/Xrps/CSRGmv oXhilabVQQ5fj+5eu3Uj4R1bhL9pl4BAWROq4xaQzdsFkDR+aoCalWJAbwrjhw== Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) (Authenticated sender: eduardo) by smtp.freebsd.org (Postfix) with ESMTPSA id 4My75j5ZmVz1Mwp for ; Wed, 26 Oct 2022 12:14:17 +0000 (UTC) (envelope-from eduardo@freebsd.org) Received: by mail-vk1-f172.google.com with SMTP id b81so7765216vkf.1 for ; Wed, 26 Oct 2022 05:14:17 -0700 (PDT) X-Gm-Message-State: ACrzQf0alSxGzyharm2UxDLK/T2Eae1qTb8E9bpW8zYHC5bspdmF4XST hl950uNTicJY4dIKYKPgafR4thpIleU+S3IIlaY= X-Google-Smtp-Source: AMsMyM5Lk4EJPteYDdvSIM9ljk7qdQIq6mcuOcHolP1dvtHDvdZ8SPu7wm24jNGKcKpFI4RRwvrUtY24HMuIjVxQh3Y= X-Received: by 2002:a1f:2dd1:0:b0:3b2:46f9:a5c8 with SMTP id t200-20020a1f2dd1000000b003b246f9a5c8mr17675307vkt.24.1666786457383; Wed, 26 Oct 2022 05:14:17 -0700 (PDT) List-Id: Porting software to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-ports List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-ports@freebsd.org X-BeenThere: freebsd-ports@freebsd.org MIME-Version: 1.0 References: <69442eed-b2e1-5be3-39f1-aef413606fcb@grosbein.net> In-Reply-To: <69442eed-b2e1-5be3-39f1-aef413606fcb@grosbein.net> From: Nuno Teixeira Date: Wed, 26 Oct 2022 13:14:05 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: sh: getting / from pwd To: Eugene Grosbein Cc: FreeBSD Mailing List Content-Type: multipart/alternative; boundary="000000000000b579e605ebeef6f7" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666786457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lcaS/sutoNQj8XOpq9zr6F0GNFn3d6k68EzFs5KVZio=; b=IhPSuCnQmVbWLatjR1iu9kG3RRHlltgGEeCZzn8NaAguJu8WYlLzG4jM0NOa5JghKVuxEY QIucGOgLHfHCVmm8zyl8e03qdnIIE6ZC57uRD6LYzZThsUDKuNwjF4xZfOZHEDRUiu3mR8 fYwQ4fbHm8tvqlweGBeG4b9MWSCc1RXE1gtVvKmiOesX/7Ktu1wqmg7HZDPCCsQ8UBujAP okvJEHTJWRxbxij3xSfxM3fZzUGcpfYTIey7tvZgqaeYbGmfKEWtI1X9E4dBT7foaDrREy 1SXjEEz4MyAl20Al5e8nV18KI3A/R4mIErnRnPQnMxoCQ3ASL/KePOphAr42/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666786457; a=rsa-sha256; cv=none; b=dbS1MXNDH9+YdF9xI+jARbBh+Aq6AWBJ14JSNxpx4n09PMqgUK7u69urEZ2bZmhDcsNye5 dNXFOEwMxLBCHG/hHiN2q38HEH0eUUBau966NxwGQTnOT9NtB5ddf2RRRn69fG6rrEUF1p 6LyAJLPFSh3Q1kxoW9bDbexlRbtFDWcvX7H9dPFMSyu+c/ozFL8rpO+xOLbOjE+wT6UVfW S/FzSqOAON7euIsQuXY7MXb/rtYfUvzijrocADKo9w5odvldUYxvvHkAdflUh3cDGAAjNP 09HPT1VVyfeevr6ngwjy0Yuzm8UDbH56wJTL3GWRgJ5b9s8nC/M0fPGCEqBP4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N --000000000000b579e605ebeef6f7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Eugene, > echo ${cwd##*/ports/} Really nice without external tools. sh: Parameter Expansion --- ${parameter#word} Remove Smallest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the smallest portion of the prefix matched by the pattern deleted. ${parameter##word} Remove Largest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest portion of the prefix matched by the pattern deleted. --- Thanks! Cheers Eugene Grosbein escreveu no dia quarta, 26/10/2022 =C3=A0(s) 05:32: > 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 / from ports tree: > >> > >> `pwd`: > >> /home/user/work/freebsd/ports// > >> > >> `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=3D$(pwd) > > echo ${cd##*/ports/} > > echo ${cwd##*/ports/} > > > This is documented in sh(1) manual page, section "Parameter Expansion". > > No need to call external tools. > > > --=20 Nuno Teixeira FreeBSD Committer (ports) --000000000000b579e605ebeef6f7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Eugene,

= > echo ${cwd##*/ports/}

Really nice without ext= ernal tools.

sh: Parameter Expansion
---=
${parameter#word}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Remove Smallest Prefix Pattern.=C2=A0 The word is expanded to produce=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0a pattern.=C2=A0 The pa= rameter expansion then results in parameter,
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0with the smallest portion of the prefix matched by the= pattern
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0deleted.
${parameter##word}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Remo= ve Largest Prefix Pattern.=C2=A0 The word is expanded to produce a
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pattern.=C2=A0 The parameter e= xpansion then results in parameter, with
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0the largest portion of the prefix matched by the pattern d= eleted.
---

Thanks!

Cheers

Eugene Grosbein <eugen@grosbein.net> escreveu no dia quarta, 26/10/2022 =C3= =A0(s) 05:32:
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 n= eed 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=3D$(pwd)
> echo ${cd##*/ports/}

echo ${cwd##*/ports/}

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




--
Nun= o Teixeira
FreeBSD Committer (ports)
--000000000000b579e605ebeef6f7--