2013-10-10 128 views
3

我寫了一個bash腳本,我得到了這些消息:bash腳本命令沒有找到 - 命令正確實施

/home/myname/documents/myscripts/run_tearingmode.sh:行44:mpirun2:找不到命令:

這裏腳本

if [[ "$run_jobs" == "y" ]] 
then 
printf "The jobs run one after the other. Have fun with the analysis. \n " 
for ((i=1;i<=$number_subfolders;i++)) 
    do 
    sub_folder=${main_folder}_$i 
    cd 
    cd gkw/run/${main_folder}/$sub_folder #change into certain subfold 
    pwd 
    mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x #run on all 8 frames #line 44 Here is the problem 
    cd 
done 
fi 

我的問題是,當我在該行,在某個文件夾只是一個命令類型,在PROGRAMM正確運行的相關部分。這向我顯示,我正確實施了它。隨着pwd我也知道我在正確的文件夾。 我沒有找到我犯了錯誤的地方。我是否需要腳本中的某個支架或類似的東西來運行程序? 我也刪除了命令前的空白,但沒有任何改變。 什麼是錯/缺少?

編輯:問題是,你不能在這樣的腳本中從bashrc運行別名。 所以我說:

mpirun2='/Path/to/mpirun' 

給我的腳本,並在腳本中改變了命令:

"$mpirun2" -np 8 ./gkw_btppx-gnu-DP_3481.x #run on all 8 frames 

這工作。 非常感謝。 (可惜我不會寫這個回答我自己作爲首發:))

+1

檢查腳本運行時環境變量(即'echo $ PATH')的'PATH'環境變量的值。指定「mpirun2」的完整路徑應該有所幫助。 –

回答

1

我想,如果你在你的腳本的頂部添加認領

#/usr/bin/env bash 

完整路徑可執行(此命令顯示它which mpirun2)這應該工作。

+0

我在我的腳本開始時有 #!/ bin/bash 。 直到我想啓動程序,我的腳本運行良好。 我也將mpirun2命名爲bashcr中的別名 alias mpirun2 ='/ home/myname/mpich2/bin/mpirun' 。該文件夾的實際路徑是什麼? – user2867054

+4

您的別名在您的腳本中不可用。替代別名,將其添加到'.profile'或'.bash_profile'(而不是'.bashrc'):'PATH =「/ home/myname/mpich2/bin/mpirun:$ PATH」'。 – chepner

1

如果mpirun2不在用戶的PATH上('哪個-a'將不返回任何內容)。您必須使用它的完整路徑調用它:

/full/path/to/mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x