2017-03-09 38 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 

我会贴更多,但它不清楚如何处理这些数据做。

希望这会有所帮助。