2017-03-09 82 views
0

通過提供命令molcas -f file.input來運行量子化學計算。我現在需要將molcas -f放入一個腳本中,該腳本也是tail是生成的file.log的最後100行,以便我快速確認所有事情都按其應有的方式完成。所以,我要運行腳本run.sh製作從命令行讀取參數的腳本

#!/bin/bash 

molcas -f [here read the file.input from command line] 
tail -100 [here read the file.log] 

問題是我怎樣才能使腳本閱讀我給的參數,然後在自己的輸出文件中找到(具有相同的文件名,但有不同的延伸)。


後續

說我有一堆編號文件file-1, file-2, ..., file-n。我會節省時間,如果我,而不是運行

./run.sh file-1.input file-1.log

我跑

./run.sh n n 

./run.sh n.input n.log 

假設數n的實際文件名和位置在給定腳本。可以這樣做嗎?

+1

請參閱http://stackoverflow.com/documentation/bash/4797/internal-variables/16884/1-2-3-etc#t=201703091327041201335和http://stackoverflow.com/documentation/bash/502/ shell-parameter-expansion/7580/replace-pattern-in-string#t = 201703091327440062742 – Sundeep

回答

1

有了這個代碼:

#!/bin/bash 
molcas -f "$1" 
tail -100 "$2" 

您需要按照以下步驟執行腳本run.sh:

./run.sh file.input file.log 
+0

很好。查看更新的問題。 – Yoda

+0

@Yoda您是否可以更新所需的輸入和輸出示例? –

0

是hornest我有/沒有任何線索超過molcas,所以我jumed到this side獲得基本的瞭解。

語法shoould這個樣子......

#!/bin/bash 

# waiting for input 
read -p "Enter a filename (sample.txt): " FILE 

# checking for existing file 
if [ -e "$FILE" ]; then 
    read -p "Enter a command for moculas: " CMD 
else 
    echo "Sorry, \"${FILE}\" was not found. Exit prgramm." 
    exit 1 
fi 

# I am not sure how this command works. 
# maybe you have to edit this line by your self. 
molcas $FILE -f "$CMD" 

# checking for programm-errors 
ERRNO=$? 
if [ "$ERRNO" != "" ] && [ "$ERRNO" -gt 0 ]; then 
    echo "Molcas returned an error. Number: ${ERRNO}" 
    exit 1 
fi 


# cuts off the fileending (For example: sample.txt gets sample) 
FILENAME="${FILE%.*}" 

# checking other files 
ERRFILE="${FILENAME}.err" 
tail -n 100 $ERRFILE 

LOGFILE="${FILENAME}.log" 
tail -n 100 $LOGFILE 


exit 0 

我會貼更多,但它不清楚如何處理這些數據做。

希望這會有所幫助。