I have a file in a folder that ends with *SUM.ext as follows
/Users/DA/xray/xmm/analyses/id_0141750501/0618_0141750501_SCX00000SUM.ext
and I have to export the path in bash_profile and source it in order to be able to do my analyses
export SOS="$anadir"/"$obsdir"/'0618_0141750501_SCX00000SUM.ext'
Here $anadir
corresponds to Users/DA/xray/xmm/analyses
and $obsdir
to id_0141750501
. On each occasion, $obsdir changes, so do the file with "SUM.ext" extension and I need to source the new file for my analyses.
I tried the following but none of them find/store the correct full filename in the directory.
1) export SOS="$anadir"/"$obsdir"/"*SUM.ext"
2) export SOS="$anadir"/"$obsdir"/`ls -1 *SUM.ext`
3) sosname="${odfdir#/*SUM.ext}"
export SOS="$sasname"
Is there a way for me to be able to do this automatically without going through the hassle of modifying my bash_profile each time for each filename?
CodePudding user response:
"*" won't expand in variable creation process, try it like this:
SOS=$(ls "$anadir/$obsdir"/*SUM.ext)
[[ $SOS ]] && export SOS