(standard_in) 1: parse error

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
renxinzhi
帖子: 970
注册时间: 2007-11-02 13:46

(standard_in) 1: parse error

#1

帖子 renxinzhi » 2012-09-07 15:01

代码: 全选

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
这两句话错在哪里了?
谢谢。
上次由 renxinzhi 在 2012-09-07 23:16,总共编辑 1 次。
明察,慎思,笃行
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: (standard_in) 1: parse error

#2

帖子 aerofox » 2012-09-07 21:07

bc 中不能用大写字母做变量吧。
echo "($n_Cu*$a_Cu+$n_N*$a_N+$n_H*$a-H-$E)/($n_Cu+$n_N+$n_H)"|bc
那个红色的H处出错,或者是前面的减号应当为下划线?
头像
renxinzhi
帖子: 970
注册时间: 2007-11-02 13:46

Re: (standard_in) 1: parse error

#3

帖子 renxinzhi » 2012-09-07 23:14

aerofox 写了:bc 中不能用大写字母做变量吧。
echo "($n_Cu*$a_Cu+$n_N*$a_N+$n_H*$a-H-$E)/($n_Cu+$n_N+$n_H)"|bc
那个红色的H处出错,或者是前面的减号应当为下划线?
那个红的H我看出来了,确实是手误。
不过,bc中倒是确实可以用大写字母做变量的,我已经用了很久了。
不过第一条命令中的第三条记录
$(echo "$s_Cu*$n_Cu+$m_NH2-($E)"|bc)
这样是没错的,去掉$E的括号就错了,而且如果再继续除以后面的东西就又会报错。
明察,慎思,笃行
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: (standard_in) 1: parse error

#4

帖子 aerofox » 2012-09-08 6:36

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
头像
renxinzhi
帖子: 970
注册时间: 2007-11-02 13:46

Re: (standard_in) 1: parse error

#5

帖子 renxinzhi » 2012-09-08 10:02

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
涉及到的文件OUTCAR,去掉了无关的部分
FREE ENERGIE OF THE ION-ELECTRON SYSTEM (eV)
---------------------------------------------------
free energy TOTEN = -71.646279 eV

energy without entropy= -71.636236 energy(sigma->0) = -71.642931
POSCAR,去掉了无关的部分
System = 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
输出文件out
-0.232790 -3.020576 -1.119520 -3.436938 -13.478475
16 1 2 19
-71.646279 3.176796
你可以自己测试一下。
明察,慎思,笃行
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: (standard_in) 1: parse error

#6

帖子 aerofox » 2012-09-08 21:24

你现在的脚本中并没有在 bc 中使用大写变量名呀。

在 bash 脚本中使用大写变量名是可以的,在 bc 中不行(至少 Debian 6.0中的 bc 版本不行)。用 $ 调用的变量在传给 bc 之前就已经由 bash 换成相应的值了。
头像
renxinzhi
帖子: 970
注册时间: 2007-11-02 13:46

Re: (standard_in) 1: parse error

#7

帖子 renxinzhi » 2012-09-08 23:43

aerofox 写了:你现在的脚本中并没有在 bc 中使用大写变量名呀。

在 bash 脚本中使用大写变量名是可以的,在 bc 中不行(至少 Debian 6.0中的 bc 版本不行)。用 $ 调用的变量在传给 bc 之前就已经由 bash 换成相应的值了。
哦,我对你的话理解错误了。
明察,慎思,笃行
回复