本文介绍了使用 scp 时 for 循环中的 @的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请看这一行:
${server_username}:${server_password}@@{server}:/tmp
双@@ 会导致问题.它显示为 user:passserver 而不是 user:pass@server,因此无法连接到远程 ssh 服务器.
The double @@ causes problems. Instead of user:pass@server it displays as user:passserver and therefore is unable to connect to the remote ssh server.
你如何告诉蚂蚁离开@be?
How do you tell ant to leave the @ be?
这是我的代码:
<for list="${externalLibs}" param="library">
<sequential>
<for list="${servers}" param="server">
<sequential>
<echo> Copying @{library} to @{server} ${server_username}:${server_password}@@@{server}:/tmp/@{library}/${@{library}}/
</echo>
<scp todir="${server_username}:${server_password}@@@{server}:/tmp/@{library}/${@{library}}/">
<fileset dir="/tmp/@{library}/${@{library}}/" />
</scp>
</sequential>
</for>
</sequential>
</for>
在 echo 命令中,它是这样显示的:
In the echo command, it shows like this:
正在将 LibraryName 复制到myserver.domain.com用户名:密码@{服务器}:/tmp/LibraryName/LibraryBar
推荐答案
你可以通过将 @
加倍来逃避 @
,就像 @@
一样.
You escape @
by doubling it, as in @@
.
所以你的情况是:
${server_username}:${server_password}@@@{server}:/tmp
顺便说一句,同样的规则适用于 $
转义,$$
只打印一个 $
.
BTW, same rule goes for $
escape, $$
just prints a $
.
回复OP的评论
示例:
<property name="server_username" value="user-name"/>
<property name="server_password" value="passwd"/>
<for list="s1.foo.bar,s2.foo.bar,s3.foo.bar" param="server">
<sequential>
<echo message="${server_username}:${server_password}@@@{server}:/tmp"/>
</sequential>
</ac>
这会产生:
[echo] user-name:passwd@s1.foo.bar:/tmp
[echo] user-name:passwd@s2.foo.bar:/tmp
[echo] user-name:passwd@s3.foo.bar:/tmp
所以,你的问题在其他地方,可能在循环设置代码中
So, your problem is somewhere else, probably in the loop setup code
这篇关于使用 scp 时 for 循环中的 @的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!