In my folder I have following files:
roi_1_Precentral_L/
roi_1_Precentral_L_both.fig
roi_1_Precentral_L_left.fig
roi_1_Precentral_L_right.fig
roi_1_Precentral_L_slice.fig
roi_2_Precentral_R/
roi_2_Precentral_R_both.fig
...
roi_116_Vermis_10/
roi_116_Vermis_10_both.fig
roi_116_Vermis_10_left.fig
roi_116_Vermis_10_right.fig
roi_116_Vermis_10_slice.fig
I use following script to obtain a desired prefix of the filename for each of all 116 types:
for iroi in `seq 1 116`;
do
d=roi_${iroi}_*/
d2=${d:0:-1} # <-- THIS LINE IS IMPORTANT
echo $d2
done;
Desired output for iroi=1:
$ roi_1_Precentral_L
Actual output:
$ roi_1_Precentral_L roi_1_Precentral_L_both.fig roi_1_Precentral_L_left.fig roi_1_Precentral_L_right.fig roi_1_Precentral_L_slice.fig
How can I avoid shell expansion in the emphasized line of code to make desired output?