Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Can I test if a parameter expansion has worked




On 15/09/2022 17:48, Bart Schaefer wrote:
On Thu, Sep 15, 2022 at 12:34 AM zzapper <zsh@xxxxxxxxxxxxxx> wrote:
print ${f/%(#m).[pjg][npi]e#[gf]/_s$MATCH}
stuff.txt  #  expansion has obviously left the input unchanged but can I
test for that???
In the general case, no, as PWS has already addressed.

In this specific case, tho, if you "unset MATCH" before doing the
substitution, you can test $+MATCH after.


Bart

Generically useful thanks (sorry late reply)

f=fred.jpg

print ${f/%(#m).[pjg][npi]e#[gf]/_s$MATCH}

echo $+MATCH

1

zzapper





Messages sorted by: Reverse Date, Date, Thread, Author