出于某种原因,此function正常工作,terminal正在输出
newbootstrap.sh: 2: Syntax error: "(" unexpected
这是我的代码(第2行是函数MovetoTarget() { )
#!/bin/bash function MovetoTarget() { #This takes to 2 arguments: source and target cp -r -f "$1" "$2" rm -r -f "$1" } function WaitForProcesstoEnd() { #This takes 1 argument. The PID to wait for #Unlike the AutoIt version,this sleeps 1 second while [ $(kill -0 "$1") ]; do sleep 1 done } function RunApplication() { #This takes 1 application,the path to the thing to execute exec "$1" } #our main code block pid="$1" SourcePath="$2" DestPath="$3" ToExecute="$4" WaitForProcesstoEnd $pid MovetoTarget $SourcePath,$DestPath RunApplication $ToExecute exit
什么是Linux中的rc.status文件
输出bash脚本的格式
BASH或PHP的服务器维护脚本?
Linux Bash。 2线有什么区别?
FOR循环variables中的空格问题 – 批处理脚本
Bash脚本:糟糕的解释器
使用脚本构build新计算机
awk脚本总是打印sum = 0
MovetoTarget() { # Function }
或这个:
function MovetoTarget { # function }
但不是两个。
另外,我看到稍后使用逗号分隔参数( MovetoTarget $SourcePath,$DestPath )。 这也是一个问题。 bash使用空格来分隔参数,而不是逗号。 删除逗号,你应该是金色的。
我也是在bash脚本中定义函数的新手。 我使用的版本是4.3.11(1): – Ubuntu 14.04上的release(x86_64-pc-linux-gnu) 。
我不知道为什么,但是以关键字function开头的定义从来不适用于我。
定义如下
function check_and_start { echo Hello }
产生错误信息:
Syntax error: "}" unexpected
如果我把{像一个新的行:
function my_function { echo Hello. }
它打印一个Hello. 当我运行脚本时,即使我根本不调用这个函数,这也是我们想要的。
我不知道为什么这不起作用,因为我也看了很多教程,他们都把开放大括号放在第一行的末尾。 也许这是我们使用的bash版本? 无论如何,只是把它放在这里为您的信息。
我必须使用C风格的函数定义:
check_and_start() { echo $1 } check_and_start World! check_and_start Hello,World!
并按预期工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。