Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Can I test if a parameter expansion has worked
On 14/09/2022 11:03, zzapper wrote:
Hi
Q1) Can I test if a parameter expansion has 'fired'?
other than by testing if input == output
Bit embarrassed I didn't provide an example :(
so here it is
# adding a prefix '_s' to an image name
f=stuff.jpg;
print ${f/%(#m).[pjg][npi]e#[gf]/_s$MATCH}
stuff_s.jpg # good this is what i want
# now pass 'bad' input
f=stuff.txt;
print ${f/%(#m).[pjg][npi]e#[gf]/_s$MATCH}
stuff.txt # expansion has obviously left the input unchanged but can I
test for that???
I suppose I should be testing the filename before passing it to the
expansion
if [[ $f =~ '.jpg|gif|png|jpeg' ]] ;then echo 'ok' ;else echo 'nok' ;fi
Messages sorted by:
Reverse Date,
Date,
Thread,
Author