0

我知道这通常与递归有关,但我很确定我没有这样做。在每次循环中,它都会给出一个指向 for 循环行的分段错误。

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

除了文件的复制之外,我认为循环与循环通过的原始文件夹没有任何联系。

这是错误:

./extract_all_projects.sh: line 26:  7500 Segmentation fault      (core dumped) 

我不知道问题是什么,因为如果在 bash 脚本之外运行,“cppapplication.exe”在这些文件上运行良好。

4

1 回答 1

0

$filename可能为空,也可能与预期不同。我确定段错误是cppapplication.exe崩溃(你为什么不告诉我们第 26 行是什么?)要对此进行测试,请尝试

./cppapplication.exe "" 0 1 1 0

看看它是否有段错误。如果我不得不猜测:该应用程序尝试打开一个文件,但不检查返回值,并且使用 NULL 指针打开士兵。

顺便说一句,脚本中除了第一个分号之外的所有内容都是无用的。外壳不是 C :-)

于 2012-10-03T18:04:57.253 回答