I'm trying to make a script that will merge two subtitles.


I have a case insensitive for matching both forced subtitles.

shopt -s extglob
shopt -s nocaseglob

for file in "${1%/}/"*forced.srt; do
   echo File: "$file"

I have this code to remove forced string from the filename, so I get the matching file to use in my script


How can I remove this string forced from my variable, case insensitive?

  • Please explain why four .srt files are listed when the goal is to merge only two files.
    – agc
    Jul 5, 2019 at 8:18

1 Answer 1


You want the nocasematch shell option here, rather than (just) nocaseglob:

If the nocasematch shell option (see the description of shopt in The Shopt Builtin) is enabled, the match is performed without regard to the case of alphabetic characters.

nocaseglob is only for true filename expansion (like you used in your for loop), but doesn't apply to other places pattern matching occurs. For your use case you actually need both enabled so that both the filename expansion and the pattern match do it.

For only those two characters in that one spot, you can use [Ff] to match both F and f there.

  • Do I use shopt -s too to enable this option?
    – Freedo
    Jul 5, 2019 at 7:45
  • Yes, it's exactly the same sort kind of thing as nocaseglob. Jul 5, 2019 at 7:46
  • Would it be possible to get an example please? Mar 31, 2022 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .