1

I want to accomplish this:

setopt HIST_SUBST_PATTERN
echo Ninja_Turtles_2003_S02E05_DVDRip_30NAMA.mkv
^E(0?)^E$((match[1]+1))
# resulting in:
echo Ninja_Turtles_2003_S02E06_DVDRip_30NAMA.mkv

‌But I get:

echo Ninja_Turtles_2003_S02E1_DVDRip_30NAMA.mkv

I tried ^(#b)E(0?)^E$((match[1]+1)), but it didn't work.

1

You need the extendedglob option for (#b).

Also 05 + 1 yields 6, not 06.

You could do (with extendedglob and histsubstpattern)

^(#b)E(<->)^E${(l:2::0:)$((match[1]+1))}

Or:

echo ${_//(#b)E(<->)/${(l:2::0:)$((match[1]+1))}
  • <-> is a form of <x-y> positive decimal number matching operator where both boundaries are omitted, so matches any non-empty sequence of decimal digits. Same as [0-9]## (though ## needs extended-glob while <x-y> doesn't).
  • (l:2::0:) (note that it's a lower case L, not the 1 digit) is the left-padding parameter expansion flag, here with 0s, of length 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.