questions > dcm2niix cannot find dicoms in files with wildcards within script
Showing 1-2 of 2 posts
Display:
Results per page:
Sep 9, 2019  09:09 PM | sciencecasey
dcm2niix cannot find dicoms in files with wildcards within script
Hi there,

When I run from command line using variables and wildcards, the following executes perfectly:

```
cd ${sourcedir}
for direcs in *fmap*; do
#grab the directories within each functional task folders
dcm2niix -b y -z y -o ${outputdir}/sub-${subj}/ses-${session}/ -f ${subj}_%p_%s ${sourcedir}/*_${subj}_S${session}/dicom/Prisma*/201*****/FEU*/${direcs}
done
```

However, when this is put within a script, I receive the following error:
```
Processing subject 8001
Chris Rorden's dcm2niiX version v1.0.20190410 Clang10.0.0 (64-bit MacOS)
Error: Unable to find any DICOM images in /Users/casey/Desktop/working_folder/bids_structure_practice/GD_study/source/*_8001_S1/dicom/Prisma*/201*****/FEU*/{*mprage*} (or subfolders 5 deep)
```

It looks as though the wildcards are being taken as explicit input rather than used as wildcards.  I have experimented with using quotations around each portion except the wildcards 
```
"${sourcedir}/"*"_${subj}_S${session}/dicom/Prisma"*"/201"*****"/FEU"*"/${direcs}"
```

and it still doesn't work.  I have modified the quotes a number of ways and it still will only find when copied and pasted directly in the terminal rather than being run as a script. 

Thanks for your help
Casey
Sep 10, 2019  12:09 PM | Chris Rorden
RE: dcm2niix cannot find dicoms in files with wildcards within script
Hello

This is the intended behavior, and is consistent with other executables on your computer. Interactive and non-interactive BASH shells do not behave the same, in particular with respect to globbing. A general web search will provide more information on this. In many situations, adding "shopt -s extglob" to a script can make a non-interactive script act more like an interactive shell. You will also want to be careful how you distinguish your escape characters from file separators (use of quotes and //).

Since your question is general to Unix scripts rather than dcm2niix, you may get better advice asking this question on a more domain general forum (e.g. StackOverflow) using a less domain specific tool. Your question is beyond the scope of this forum, as this is a Unix scripting question not a dcm2niix question. I have very little expertise with Unix scripts, and that is probably true of most of the people who follow this forum.