Wednesday 28 March 2007

我的第一个Unix Shell程序--first principle theroy(pseupotiential)

ecut=1

incre=1

while [ $ecut -lt 71 ] #注意判断语句用[]包住,同时注意括号内侧的空格
do
   echo ecut is $ecut
 
   ~pap512/espresso-2.1.5/bin/pw.x < si.in  > si.out.${ecut} #执行文件读取参数,和输出文件。注意:如果$引导的变量直接与其他字符相接要用${}的格式

   ecut_temp=`expr $ecut + $incre` #最变态的地方
                   #这里用的不是单引号,而是'~'键对应的按键的""!用以讲表达式作为参数输给一个变量
                   #unix基本都是字符操作,如果进行运算,要用expr,将起放在变量前面,以得到运算结果,否则只会将字符串连接起来

     #或者改写为:(( ecut_temp=$ecut + $incre ))。这个命令等效于let命令。可以在(( ))之间写表达式进行混合计算。
   echo ecut_temp is $ecut_temp

   sed -e "12s/$ecut/$ecut_temp/" si.in | cat > si.temp;cat si.temp > si.in #这里注意必须用双引号就是了,而不是默认的单引号。单引号就屏蔽了变量饮用,只是认为内部是字符
  
   ecut=$ecut_temp
  
done
echo all done

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter