更新时间:2023-02-07 12:13:09
只要把你的功能在这里文档中,也:
Just put the functions in your here document, too:
var="Hello World"
ssh user@host <<END
x() {
print "x function with args=$*"
}
x "$var"
END
一些评论:
您说的出口JBOSS_HOME但你永远不为这里文档中变量定义值。您应该使用出口JBOSS_HOME =$ JBOSS_HOME
。 BASH将采取两个 END之间的所有文字
,更换所有的变量,并将结果发送到SSH进行处理。
You say "export JBOSS_HOME" but you never define a value for the variable in the here document. You should use export JBOSS_HOME="$JBOSS_HOME"
. BASH will take all text between the two END
, replace all variables, and send the result to SSH for processing.
这也意味着对方会看到 RM -f /路径/要/ JBoss的/服务器/ *登录
。在这里文件的最后一行分配给 JBOSS_SERVER
在无影响(至少还没到code清理()
)。
That also means the other side will see rm -f /path/to/jboss/server/*.log
; the assignment to JBOSS_SERVER
in the last line of the here document has no effect (at least not to the code in cleanup()
).
如果你想通过 $
未修改到远程服务器,您有来逃避它\\
: RM -f \\ $ JBOSS_SERVER /日志/ *。登录
If you want to pass $
unmodified to the remote server, you have to escape it with \
: rm -f \$JBOSS_SERVER/log/*.log
您永远不会调用清理()
有一个}
后失踪返回0
来完成的定义 deployapp()
There is a }
missing after return 0
to finish the definition of deployapp()
有可能有其他问题为好。运行带有的bash -x
剧本,看看有什么外壳实际执行。您还可以添加此文档中回声
命令来查看哪些变量的值,也可以添加设置-x
在清理()
来得到相同的输出与的bash -x
但是从远程端。
There may be other problems as well. Run the script with bash -x
to see what the shell actually executes. You can also add echo
commands in the here document to see what the values of the variables are or you can add set -x
before cleanup()
to get the same output as with bash -x
but from the remote side.