我通过提供命令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的位置。那能办到吗?
发布于 2017-03-09 13:29:24
使用此代码:
#!/bin/bash
molcas -f "$1"
tail -100 "$2"需要执行脚本run.sh,如下所示:
./run.sh file.input file.log发布于 2017-03-09 14:02:35
最可怕的是,我对molcas毫无头绪,所以我跳槽到这边,以获得基本的理解。
语法应该是这样的。
#!/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我会发布更多,但它不清楚如何处理这些数据。
希望这能帮点忙。
https://stackoverflow.com/questions/42696598
复制相似问题