代码: 全选
echo "$i-$k $E $(echo "($s_Cu*$n_Cu+$m_NH2-$E)/($n_Cu+$n_N+$n_H)"|bc)">>adsorption
echo "$i-$k $E $(echo "($n_Cu*$a_Cu+$n_N*$a_N+$n_H*$a_H-$E)/($n_Cu+$n_N+$n_H)"|bc)">>binding
代码: 全选
(standard_in) 1: parse error
谢谢。
代码: 全选
echo "$i-$k $E $(echo "($s_Cu*$n_Cu+$m_NH2-$E)/($n_Cu+$n_N+$n_H)"|bc)">>adsorption
echo "$i-$k $E $(echo "($n_Cu*$a_Cu+$n_N*$a_N+$n_H*$a_H-$E)/($n_Cu+$n_N+$n_H)"|bc)">>binding
代码: 全选
(standard_in) 1: parse error
那个红的H我看出来了,确实是手误。aerofox 写了:bc 中不能用大写字母做变量吧。
echo "($n_Cu*$a_Cu+$n_N*$a_N+$n_H*$a-H-$E)/($n_Cu+$n_N+$n_H)"|bc
那个红色的H处出错,或者是前面的减号应当为下划线?
这样是没错的,去掉$E的括号就错了,而且如果再继续除以后面的东西就又会报错。$(echo "$s_Cu*$n_Cu+$m_NH2-($E)"|bc)
man bc 写了:VARIABLES
Numbers are stored in two types of variables, simple variables and arrays. Both
simple variables and array variables are named. Names begin with a letter followed
by any number of letters, digits and underscores. All letters must be lower case.
(Full alpha-numeric names are an extension. In POSIX bc all names are a single lower
case letter.) The type of variable is clear by the context because all array vari‐
able names will be followed by brackets ([]).
代码: 全选
bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
H=1
(standard_in) 1: illegal character: H
(standard_in) 1: syntax error
不知道是不是我理解有误,但我使用大写字母做变量真的已经很久了。我这次出错的部分涉及到的命令aerofox 写了:man bc 写了:VARIABLES
Numbers are stored in two types of variables, simple variables and arrays. Both
simple variables and array variables are named. Names begin with a letter followed
by any number of letters, digits and underscores. All letters must be lower case.
(Full alpha-numeric names are an extension. In POSIX bc all names are a single lower
case letter.) The type of variable is clear by the context because all array vari‐
able names will be followed by brackets ([]).代码: 全选
bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. H=1 (standard_in) 1: illegal character: H (standard_in) 1: syntax error
代码: 全选
#!/bin/bash
a_Cu=-0.232790 #the energy of atom Cu
a_N=-3.020576 #the energy of atom N
a_H=-1.119520 #the energy of atom H
s_Cu=-3.436938 #the energy of Cu(100) surface(per atom)
m_NH2=-13.478475 #the energy of NH2
E=`grep "TOTEN" OUTCAR | tail -1 | awk '{printf "%-.6f \n",$5}'`
n_Cu=`cat POSCAR | head -7 | tail -1 | awk '{printf "%-2d \n",$1}'` #the number of Cu
n_N=`cat POSCAR | head -7 | tail -1 | awk '{printf "%-2d \n",$2}'` #the number of N
n_H=`cat POSCAR | head -7 | tail -1 | awk '{printf "%-2d \n",$3}'` #the number of H
echo "$a_Cu $a_N $a_H $s_Cu $m_NH2">>out
echo "$n_Cu $n_N $n_H $(echo "($n_Cu+$n_N+$n_H)"|bc)">>out
ads=$(echo "$s_Cu*$n_Cu+$m_NH2-($E)"|bc)
echo "$E $ads">>out
POSCAR,去掉了无关的部分FREE ENERGIE OF THE ION-ELECTRON SYSTEM (eV)
---------------------------------------------------
free energy TOTEN = -71.646279 eV
energy without entropy= -71.636236 energy(sigma->0) = -71.642931
输出文件outSystem = Cu(111) NH2
1.0
5.0840835571 0.0000000000 0.0000000000
-2.5420423649 4.4029451769 0.0000000000
0.0000000000 0.0000000000 17.0690555573
Cu N H
16 1 2
你可以自己测试一下。-0.232790 -3.020576 -1.119520 -3.436938 -13.478475
16 1 2 19
-71.646279 3.176796
哦,我对你的话理解错误了。aerofox 写了:你现在的脚本中并没有在 bc 中使用大写变量名呀。
在 bash 脚本中使用大写变量名是可以的,在 bc 中不行(至少 Debian 6.0中的 bc 版本不行)。用 $ 调用的变量在传给 bc 之前就已经由 bash 换成相应的值了。