shopt -s extglob
for i in *.dat;
if [[ "$i" == *(_TEx) ]];then
$ shellcheck myscript
No issues detected!
milenko@milenko-HP-Compaq-6830s:~/procmt$ bash a8.sh
The minimal modification to your attempt to make it work would be this:
if [[ "$i" == *_TEx* ]]; then
i.e. remove the parentheses and add the missing
* at the end of the pattern. There's no need to set the
extglob shell option, as you don't need to use any of its features.
However, you might as well change the glob that your are looping over to this:
for i in *_TEx*.dat;
and avoid the
Better yet, you could just print the matches directly:
shopt -s nullglob printf '%s\n' *_TEx*.dat # print all files matching the pattern
nullglob is useful here as it will result in no output when no files match the pattern.