set variable using 'ls' with an 'or' conditional statement

Hi,

I would like to set a variable using ls, but I need to be able to list two possibilities simultaneously, i.e., I'd like to do this all on one line. These are the two possible directories, but keep in mind only *one* will be present at any given time:

drwxrwxrwx 4 qtv qtv 16384 Nov 9 15:26 t2_tirm_tra_dark_fluid_5mm
drwxrwxrwx 4 qtv qtv 16384 Nov 9 15:26 FLAIRmosaic

So the code needs to be able to list one or the other at any given time and not error out when it sees that the other does not exist. This is what I've tried so far:

dir=`ls -d ./*FLAIR* ./*dark*`

This command errors out when the top dir doesn't contain one of the two directories. Any suggestions would be greatly appreciated. Thanks!

Hi

Try this:

dir=`ls -d ./*FLAIR* ./*dark* 2> /dev/null`

Guru.

Thanks Guru. It prevented the output of any error messages, but the variable was empty unfortunately. I'll keep working on this, thanks anyway!

find . -type d |egrep "FLAIR|dark"

Hi,

bash can do this:

dir=$(shopt -s extglob nullglob; echo ./*?(FLAIR*|dark*))

check your shell's man page, to see if something similar exists.

Try this,

dir=`find . -type d -name "*FLAIR*" -o -type d -name "*dark*"`