【发布时间】:2019-04-16 15:12:17
【问题描述】:
我正在尝试在 bash 上运行以下代码,但每次我遇到错误(无效的算术运算符)时,谁能帮忙
#!/bin/bash
for i in $(seq 20);
do
k=$(($i/100))
a=$((4.18+$k))
b=$(($a+0.01))
siesta < BiTeI.fdf > out_file #do the operation
lineno=939 # set the line number where the data you want to read is in
newline=$(sed -n "${lineno}p" "out_file") # asign a veriable for the line from the txt file note to change the file name
echo $newline >> output.txt # print the line extracted to an out put file note to generate file before adding to it
sed -i "30s/$a/${b}/" BiTeI.fdf # update the input file for new parameters for a specific raw
done
【问题讨论】:
-
我试过这个,但每次都说 bc: command not found
-
很难相信您的系统上没有安装
bc。uname -srv的输出是什么?您更有可能覆盖了正常的$PATH变量。启动一个新终端,并发出以下 cmdecho $PATH。你看到像/bin:/usr/bin:/sbin:/usr/sbin这样的名字吗?你应该。如果您这样做了,现在查看bc是否可用,即。which bc。如果它现在在那里,那么查看你的脚本,看看你在哪里重置 PATH,你需要export PATH="/new/dir:$PATH"。祝你好运。
标签: bash floating-point date-arithmetic