
#!/bin/bash
# pre.sh revision 4.0.0 Date: 2011/12/24
### Path ###
FASTAR_DIR=$(cd $(dirname $0);pwd)
##### Function s #####
. ${FASTAR_DIR}/"script.func"
usage(){
echo "Usage: " $COMNAME " [option]"
echo " option : <NONE> ...... by 1 process"
echo " -n <CPUs> ... batch process by <CPUs> process"
echo " -all ........ batch process"
echo " -e .......... use exact wall distance mode"
echo " -metis ...... use pre-fastar metis version"
echo " -fsi ........ use pre-fastar metis version with FSI mode"
echo " -emetis ..... use pre-fastar metis version with exact wd mode"
echo " -efsi ....... use pre-fastar metis version with FSI and exact wd mode"
echo " -h .......... show this statement"
}
##### Function e #####
#======================================#
# Main #
#======================================#
#=== initialize ===#
COMNAME=`basename $0`
set_variables
if [ $# -eq 1 ]; then
case $1 in
"-all" | "-e" | "-metis" | "-fsi" | "-emetis" | "-efsi") opt=$1 ;;
"-h") usage; exit ;;
*) usage; exit ;;
esac
cpu=1
elif [ $# -eq 2 ]; then
case $1 in
"-n") opt=$1 ;;
*) usage; exit ;;
esac
if [ $2 -ge 1 ]; then
cpu=$2
else
cpu=1
fi
elif [ $# -gt 2 ]; then
usage; exit
else
opt="hoge"
cpu=1
fi
#=== read inputfile ===#
read_input
case $reorder in
".true." | ".TRUE." | "T" | "t")
reorder_check="TRUE"
;;
*)
reorder_check="FALSE"
;;
esac
#=== ABORT ===#
trap 'abort 1 $COMNAME' 1 2 3 9 15
#=== Make directories ===#
make_dir
#=== preprocess ===#
if test $opt = "-all" ;then
echo $NPREFAST...
rm -f $TMP_FILE
if [ $domain -ge 2 ]; then
n_loop=$domain
id=1
for ((id=1; id<=$n_loop; id++))
do
echo "$NPREFAST $id > $TMP_FILE$id &"
$PREFAST $id > $TMP_FILE$id &
done
wait
i=1
for ((i=1; i<=$domain; i++))
do
cat $TMP_FILE$i >> $TMP_FILE
rm -f $TMP_FILE$i
done
elif [ $domain -eq 1 ]; then
$PREFAST
echo ""
else
echo "ERROR: It is wrong that total number of domain in $INPUT."
exit
fi
elif test $opt = "-n"; then
echo $NPREFAST...
rm -f $TMP_FILE
n_loop=`expr $domain / $cpu`
id=1
i=1
for ((i=1; i<=$n_loop; i++))
do
var=`expr $cpu \* \( $i - 1 \) + 1`
id=$var
j=1
for ((j=1; j<=$cpu; j++))
do
echo "$NPREFAST $id > $TMP_FILE$id &"
$PREFAST $id > $TMP_FILE$id &
id=`expr $id + 1`
done
wait
done
if [ `expr $id - 1` -lt $domain ]; then
while [ $id -le $domain ];
do
echo "$NPREFAST $id > $TMP_FILE$id &"
$PREFAST $id > $TMP_FILE$id &
id=`expr $id + 1`
done
wait
fi
i=1
for ((i=1; i<=$domain; i++))
do
cat $TMP_FILE$i >> $TMP_FILE
rm -f $TMP_FILE$i
done
elif test $opt = "-e" ;then
echo $NPREFAST...
rm -f $TMP_FILE
$PREFAST -e
elif test $opt = "-metis" ;then
echo $NPREMETIS...
rm -f $TMP_FILE
$PREMETIS
elif test $opt = "-fsi" ;then
make_dir_fsi
echo $NPREMETIS...
rm -f $TMP_FILE
$PREMETIS FSI
elif test $opt = "-emetis" ;then
echo $NPREMETIS...
rm -f $TMP_FILE
$PREMETIS -e
elif test $opt = "-efsi" ;then
make_dir_fsi
echo $NPREMETIS...
rm -f $TMP_FILE
$PREMETIS -eFSI
else
echo $NPREFAST...
rm -f $TMP_FILE
$PREFAST
fi
#=== reorder ===#
case $reorder_check in
"TRUE")
echo $NREORDGRID...
$REORDGRID
echo $NREORDINDX...
$REORDINDX
;;
esac
exit
我嘗試執行 shell 腳本,但出現以下錯誤:
[gakubu@localhost Kenkyuu]$ pre.sh
/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre。 /pre.sh:第30 行:set_variables:找不到指令/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre.sh:行:read_input:找不到指令/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/prepre .sh:行: make_dir:找不到指令
…
[gakubu@localhost Kenkyuu]$
enter code here
這是什麼意思以及如何解決這個問題?
答案1
該腳本的第 8 行包含以下程式碼:
. ${FASTAR_DIR}/"script.func"
這會將檔案來源到特定目錄。該檔案可能包含 shell 函數定義。根據錯誤訊息,找不到該文件,並且找不到該文件的影響是找不到它定義的函數(這些是您收到的“命令未找到”錯誤)。
script.func
假定該檔案與腳本本身位於同一目錄中。如果您已將腳本移至目前所在位置,但忘記將檔案script.func
也隨之移動,這可能是導致錯誤的原因。
我不會進一步評論腳本本身,只是說它使用不含引號的變數擴展使其非常脆弱,並且可能不安全。