Search code examples
arrayssetglobcshno-match

csh set: no match error wildcard


trying to look up files in directories with wildcard *, and put the names into an array

the files have similar names (MATCHr1, MATCHr2 ... )

the problem arises when the file does not exist (which is a possibility)

set command returns a "no match" error and terminates the loop

if this happens how can i get it handle the error by jumping to the next iteration?

set SUBIDS = (10003 10005 10006)

foreach SUBID ($SUBIDS)

foreach SEQR ( MATCH ENC NBACK SIMON FACE )

ls -l  *${SEQR}*.nii.gz

set Array = *${SEQR}*.nii.gz

echo $Array[*]

....rest of code works to use contents of Array to create text files and works great when the *${SEQR}*.nii.gz returns a file name

but fails when the no matches are made with the wildcard

Any help would be well apreciated

thanks!


Solution

  • you can do you ls and check the $status (or $STATUS, depends on your system) flag:
    ls -l *${SEQR}*.nii.gz >> /dev/null ; if !$status then ...