csh set: no match error wildcard

為{幸葍}努か 提交于 2020-01-07 03:22:44

问题


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!


回答1:


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 ...



来源:https://stackoverflow.com/questions/42261228/csh-set-no-match-error-wildcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!