gpt4 book ai didi

linux - 如何将bash变量传递给cmd?

转载 作者:太空宇宙 更新时间:2023-11-04 10:37:34 25 4
gpt4 key购买 nike

如何将 $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 作为命令的输入显式传递,因为一旦远程命令应从标准输入读取 -无论出于何种原因 - 否则它将吞噬 while 循环的标准输入:

while read line ; do
ssh ... -- "${line} ..." < /dev/tty # Pass tty to stdin
done < input.txt

注意:以上命令只有在进程已经在终端中启动时才有效。如果该进程未在终端中运行,您需要传递其他内容作为内部 ssh 命令的标准输入。

关于linux - 如何将bash变量传递给cmd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36734600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com