I have an array of files underneath the immediate subdirectories:
> niis=$(find . -type f)
> echo $niis
./123_20101203/123_20101203_0002_t1_mpr_AX_MPRAGE.nii.gz ./456_20140306/456_20140306_0002_t1_mpr_AX_MPRAGE.nii.gz ./789_20160723/789_20160723_0005_t1_mpr_AX_MPRAGE.nii.gz
However, when I have a loop that creates substrings based on the array values, I only get the first entry printed out:
> for n in "${niis[@]}"
> do
> echo $n
> subjid=${n:2:15}
> echo $subjid
> done
./123_20101203/123_20101203_0002_t1_mpr_AX_MPRAGE.nii.gz ./456_20140306/456_20140306_0002_t1_mpr_AX_MPRAGE.nii.gz ./789_20160723/789_20160723_0005_t1_mpr_AX_MPRAGE.nii.gz
123_20101203
How can I make sure that subjid
accounts for all three of these array values? I tried switching some syntax and then I get the same output for both n
and subjid
.
> for n in "${niis[@]}"
> do
> echo $n
> subjid=${n:2:15}
> echo $subjid
> done
./123_20101203/123_20101203_0002_t1_mpr_AX_MPRAGE.nii.gz ./456_20140306/456_20140306_0002_t1_mpr_AX_MPRAGE.nii.gz ./789_20160723/789_20160723_0005_t1_mpr_AX_MPRAGE.nii.gz
./123_20101203/123_20101203_0002_t1_mpr_AX_MPRAGE.nii.gz ./456_20140306/456_20140306_0002_t1_mpr_AX_MPRAGE.nii.gz ./789_20160723/789_20160723_0005_t1_mpr_AX_MPRAGE.nii.gz