Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to have consecutive or operators in bash?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading