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

Re: Expanding when matching



On Fri, Apr 23, 2004 at 11:15:40PM +0200, DervishD wrote:
>     $ testvar="This is my test var"
>     $ print ${testvar/var%/Replaced}
>     This is my test var

This should be:

    $ print ${testvar/%var/Replaced}
    This is my test Replaced

The leading '%' indicates that the match must occur at the end.

> What I want is the substitution (and the postincrement) expanded and
> run only when the parameter matches

If you don't need it done in a single line, you can always use "case":

counter=0
for number in {1..100}; do
    case $number in
    *0) print "Hit a ten! $((counter++))" ;;
    *)  print $number ;;
    esac
done

..wayne..



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