无法通过SSH在heredoc或命令中使用本地和远程变量

无法通过SSH在heredoc或命令中使用本地和远程变量,第1张

无法通过SSH在heredoc或命令中使用本地和远程变量

$
如果您不想扩展变量,则需要转义符号

$ x=abc$ bash <<EOF> x=def> echo $x   # This expands x before sending it to bash. Bash will see only "echo abc"> echo $x  # This lets bash perform the expansion. Bash will see "echo $x"> EOFabcdef

因此,在您的情况下:

ssh user@host bash << EOF# run script with output...REMOTE_PID=$(cat $FILE_NAME)echo $REMOTE_PIDEOF

或者,您也可以使用带单引号的herestring:

$ x=abc$ bash <<< '> x=def> echo $x  # This will not expand, because we are inside single quotes> 'def


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5009887.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存