Using POSIX standard sh
syntax, which would also be valid in bash
, you could use a case
statement here:
case $fl in
*img*|*jpg*|*png*|*tif*)
mv -- "$flimg" "$out"
esac
or, as a "one-liner",
case $fl in (*img*|*jpg*|*png*|*tif*) mv -- "$flimg" "$out"; esac
If you enable the extglob
shell option with shopt -s extglob
, you may also use
[[ $fl == *@(img|jpg|png|tif)* ]] && mv -- "$flimg" "$out"
If you only want to test a filename suffix after the last dot in the filename in $fl
:
case ${fl##*.} in (img|jpg|png|tif) mv -- "$flimg" "$out"; esac
or, after shopt -s extglob
,
[[ ${fl##*.} == @(img|jpg|png|tif) ]] && mv -- "$flimg" "$out"
The standard expansion ${variable##pattern}
removes the longest prefix string from $variable
that matches pattern
. Using *.
as the pattern means deleting everything up to and including the last dot in the value.
Note at that all pattern matches done in this answer are by means of shell patterns, not regular expressions.
$fl
and$flimg
? – Oct 21 '21 at 01:27