有没有办法在生成的命令中使用 Expect-Lite 变量?
我一直致力于尝试自动化在构建机器上构建源代码的复杂过程,然后将编译后的图像文件传输到我的嵌入式 ARMv7 设备以进行刷新。每个步骤本身都很容易使用标准 Linux Shell 脚本实现自动化,但当尝试在一个巨大的脚本中完成所有操作时,事情就会变得复杂。到目前为止,我一直在使用 Expect-lite 来完成这项工作,它正在工作,只是现在我遇到了问题。当传输图像时,我有expect-lite代码,如下所示:
$imageDestination="/the/destination"
$imageSource="/the/source/"
>sftp $userName'@'$buildMachine
>$password
>get $imageSource'/'x-load_sdcard.bin.ift $imageDestination'/'MLO
>echo "Finished"
>bye
如果您对expect-lite略知一二,那么您就会知道上述变量将被读取为“Shell”变量。问题是据我所知 SFTP 不允许使用变量。有没有办法告诉expect-lite使用预定义的变量而不是尝试使用“Shell”变量?或者,是否有一些更有效的方法可以在不删除变量的情况下绕过此限制?
非常感谢所有帮助。
I've been working on trying to automate the complicated process of building source code on a build machine and then transferring the compiled image files over to my embedded ARMv7 device to be flashed. Each step by itself is easy to automate with standard Linux Shell Script, but when trying to do everything in one giant script things get complicated. Thus far I've been using expect-lite to do the work, which is working except now I've run into a problem. When transferring the images over I have expect-lite code that looks like the following:
$imageDestination="/the/destination"
$imageSource="/the/source/"
>sftp $userName'@'$buildMachine
>$password
>get $imageSource'/'x-load_sdcard.bin.ift $imageDestination'/'MLO
>echo "Finished"
>bye
If you know a thing or two about expect-lite, then you'll know that the above variables will be read as "Shell" variables. The problem is that as far as I know SFTP doesn't allow the use of variables. Is there a way to tell expect-lite to use the predefined variables instead of trying to use "Shell" variables? Or, is there some cleaver way to get around this limitation without removing the variables?
All help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Dreligor,
不存在范围问题。 Expect-lite 变量都是全局范围的(如文档中所述)。我认为问题在于您使用了引号,这使事情变得更加困难。你应该尝试:
Craig Miller - Expect-lite 的作者和维护者
Dreligor,
There is no scope issue. Expect-lite variables are all of global scope (as stated in the documentation). I think the problem is that you are using quotes which is making things more difficult. You should try:
Craig Miller - author and maintainer of expect-lite
经过一些实验,发现这是一个范围问题。解决方案是将变量声明向下移动。它们需要在脚本通过 sftp 连接到远程计算机后声明。固定代码如下:
希望这对其他人有帮助。
After some experimentation it turns out that this is a scope issue. The solution is to simply move the variable declarations down. They need to be declared after the script has connected to the remote machine via sftp. The fixed code is as follows:
Hopefully this will help others.