Determine how many subbtitle tracks are in MKV file

Hello, I am attempting to set the default flag to 0 on ALL subtitle tracks. I tried the following, but if one MKV file in the folder does not contain 28 tracks it throws an error. Is there a way to either set ALL tracks, or at least figure out how many tracks so I can iterate in bash?
Thank you.

for f in *.mkv; do
    mkvpropedit "$f" \
      --edit track:s1 --set flag-default=0 \
      --edit track:s2 --set flag-default=0 \
      --edit track:s3 --set flag-default=0 \
      --edit track:s4 --set flag-default=0 \
      --edit track:s5 --set flag-default=0 \
      --edit track:s6 --set flag-default=0 \
      --edit track:s7 --set flag-default=0 \
      --edit track:s8 --set flag-default=0 \
      --edit track:s9 --set flag-default=0 \
      --edit track:s10 --set flag-default=0 \
      --edit track:s11 --set flag-default=0 \
      --edit track:s12 --set flag-default=0 \
      --edit track:s13 --set flag-default=0 \
      --edit track:s14 --set flag-default=0 \
      --edit track:s15 --set flag-default=0 \
      --edit track:s16 --set flag-default=0 \
      --edit track:s17 --set flag-default=0 \
      --edit track:s18 --set flag-default=0 \
      --edit track:s19 --set flag-default=0 \
      --edit track:s20 --set flag-default=0 \
      --edit track:s21 --set flag-default=0 \
      --edit track:s22 --set flag-default=0 \
      --edit track:s23 --set flag-default=0 \
      --edit track:s24 --set flag-default=0 \
      --edit track:s25 --set flag-default=0 \
      --edit track:s26 --set flag-default=0 \
      --edit track:s27 --set flag-default=0
done

Welcome!

mkvmerge has an identification functionality exactly for this type of purpose: mkvmerge --identification-mode json --identify yourfile.mkv or its shortcut mkvmerge -J yourfile.mkv

Thank you. Using that, the following code did the trick of disabling all subtitles.

for f in *.mkv; do
    subtitle_count=$(mkvmerge -J "$f" | grep -o '"type": "subtitles"' | wc -l)
    for i in $(seq 1 $subtitle_count); do
        mkvpropedit "$f" --edit track:s$i --set flag-default=0
    done
done