[英]How to pass bash variable to cmd?
如何将$line
传递给cmd
命令?
#!/bin/bash
while read line
do
sshpass -p "..." ssh -o StrictHostKeyChecking=no -tt windows@172....-p 333 cmd /c "cd C:\ & download_give_id.exe '$@$line' "
done <apps.txt
基本上,如果要将变量插值到bash字符串中,则需要使用双引号而不是单引号:
str="${var} foo bar" # works
str='${var} for bar' # works not
在特殊情况下,如果您在while循环内运行ssh命令,我强烈建议显式传递/dev/tty
作为命令的输入,因为一旦远程命令应从stdin中读取(无论出于何种原因),它将使stdin吞噬while循环,否则:
while read line ; do
ssh ... -- "${line} ..." < /dev/tty # Pass tty to stdin
done < input.txt
注意:仅当在终端中启动了进程时,以上命令才有效。 如果该进程未在终端中运行,则需要将其他内容作为stdin传递给内部ssh命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.