I understand this is usually to do with recursion, except I am pretty sure I am not doing this.
On each time round the loop it gives a segmentation error pointing to the for loop’s line.
for file in $DATAFOLDER*; do
echo $file;
filename=$(basename $file);
echo $filename;
echo "$DESTFOLDER$SUBFOLDER${filename%%.*}"
pwd
# move data to cppapplication folder
cp -R "$file" "$DESTFOLDER";
sleep 1
# create subdirectory
mkdir "$SUBFOLDER";
# create new folder for extracted data
mkdir "$DESTFOLDER$SUBFOLDER${filename%%.*}";
# copy MassLynx header file into new folder (get the description info)
cp "$file/_HEADER.TXT" "$DESTFOLDER$SUBFOLDER${filename%%.*}";
# run the cppapplication
# <program> <project file> <MassSpectrum> <Mobilogram> <bins in Da> <extract m/z ranges>
./cppapplication.exe "$filename" 0 1 1 0 ;
# fix last character comma bug
sed -i '$ s/,$//g' MassMobility.txt
# move the created files into the new folder
mv Mobilogram.txt "$DESTFOLDER$SUBFOLDER${filename%%.*}";
mv MassMobility.txt "$DESTFOLDER$SUBFOLDER${filename%%.*}";
mv MassMobilityXaxis.txt "$DESTFOLDER$SUBFOLDER${filename%%.*}";
mv MassMobilityYaxis.txt "$DESTFOLDER$SUBFOLDER${filename%%.*}";
# get driftscope quicklook image
sleep 3
python "C:\Users\ganesh\Dropbox\PhD\03_Amphitrite\CppApplication\quicklook_driftscope.py" "$DESTFOLDERWINDOWS$SUBFOLDERWINDOWS" "${filename%%.*}" "$DESTFOLDERWINDOWS$SUBFOLDERWINDOWS${filename%%.*}";
# remove MassLynx Project
rm -r "$filename";
done
Aside from the copying of the file, I don’t think the loop has any contact with the original folder being looped through.
This is the error:
./extract_all_projects.sh: line 26: 7500 Segmentation fault (core dumped)
I have no idea what the problem is as “cppapplication.exe” works fine on these files if run outside of the bash script.
Your
$filenamecould be empty or not as expected. I’m sure the segfault is thecppapplication.execrashing (Why didn’t you tell us what line 26 is?) To test this, tryand see if it segfaults. If I had to guess: the app tries to open a file but doesn’t check the return value and soldiers on with a NULL pointer.
BTW, all except the first semicolon in your script are useless. The shell is not C 🙂