Home > Software design >  Is it possible to have consecutive or operators in bash?
Is it possible to have consecutive or operators in bash?

Time:11-19

Currently I have

if [[ $INPUT_FILE == *".aac" ]] || [[ $INPUT_FILE == *".aiff" ]] || [[ $INPUT_FILE == *".pcm" ]]

I have tried the following, which does not work. It does not match anything.

if [[ $INPUT_FILE == *".aac" || *".aiff" || *".pcm" ]]

Is there any way to factor this expression?

CodePudding user response:

With [[ you could use a regex (specifically, an Extended Regular Expression)

if [[ $input_file =~ \.(aac|aiff|pcm)$ ]]; then
  : something
fi

or an extglob

if [[ $input_file = *.@(aac|aiff|pcm) ]]; then
  : something
fi

Or you may use a case statement

case $input_file in
 *.aac | *.aiff | *.pcm )
   # anything
 ;;
esac
  • Related