如何使用shell腳本執行exe?

如何使用shell腳本執行exe?

我有一個 exe,它需要 2 個 .csv 檔案作為輸入。如下:

cSplittinglines.exe srcdir\file.csv destdir\file.csv

如何使用 shell 腳本執行此 .exe,以便執行腳本的目錄不會影響 exe 的位置。又稱避免對 exe 路徑進行硬編碼。以下是我正在編寫的腳本。

#!/bin/sh
STARTTIME=`date '+%Y%m%d.%H%M%S'`

LOGFILE=${ERRDIR}/${0}.${STARTTIME}

SplitDir=$1

LyxlamDir=$2

echolog ()
{
    echo $*
    echo $* >> ${LOGFILE}
}

    for file in "${SplitDir}"/*; do
    if [ -d "$file" ]; then continue; fi
    extension=${file##*.}

    if [ "$extension" = "csv" ]
    then    
        cSplittingLines.exe "$file" "${LyxlamDir}"
        mv "$file" "${SplitDir}/old"

    fi
done

答案1

只需將 exe 放在 $PATH 中(這就是它的用途)(Windows 上為 %PATH%)

mv cSplittingLines.exe /bin/

或者

echo "export PATH=\"\$PATH:/path/to/exe\"" >> ~/.bashrc

https://www.shellcheck.net說;

SC2006: Use $(...) notation instead of legacy backticked `...`.
SC2086: Double quote to prevent globbing and word splitting.

相關內容