Bash脚本错误。这个脚本有什么问题?

时间:2014-05-04 19:47:51

标签: bash

我是bash脚本编写的新手,我有这个错误。我到处寻找找不到答案的答案。这个脚本有什么问题?

#!/bin/bash 

exec >> /Users/k_herriage/bin/post-gererate.out 2>&1
date
set -x

mynewfile="~/bin/convert_tst.txt"

myfile=fopen($mynewfile,'w+' );
#echo $myfile

    fwrite($myfile, "testing");
    fclose($myfile);

exit (0)


line 7: syntax error near unexpected token `('
line 7:`myfile = fopen ( '~/bin/convert_tst.txt','w' );'

1 个答案:

答案 0 :(得分:0)

几点:

  • 在bash中调用函数不需要parens,它在语法上等同于命令:

    do_something arg1 arg2 arg3
    
  • 不需要在bash中执行open-append-close序列,只需一个命令即可:

    echo "testing" >> $mynewfile; ##
    

    >>表示"追加",如果是>,则表示"覆盖"或"丢弃内容"。 (如果文件不存在,两者都将创建该文件。)

相关问题