Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何使用本地的参数运行远程bash脚本_Linux_Bash_Shell_Scripting - Fatal编程技术网

Linux 如何使用本地的参数运行远程bash脚本

Linux 如何使用本地的参数运行远程bash脚本,linux,bash,shell,scripting,Linux,Bash,Shell,Scripting,我对shell脚本还不熟悉,有点小麻烦 我正在尝试从本地计算机执行远程脚本。向本地计算机上的脚本传递四个参数,并执行以下行: ssh $STACK 'bash -l -c "./deploy_intermediate.sh $2 $3 $4"' 但是,我无法获得2美元、3美元和4美元来输出传递的参数。有没有办法在单引号内访问它们?执行上述行的最佳方式是什么 我真的很感激任何帮助 谢谢。要传递参数,您必须写入: ssh $STACK 'bash -l -c "./deploy_intermedi

我对shell脚本还不熟悉,有点小麻烦

我正在尝试从本地计算机执行远程脚本。向本地计算机上的脚本传递四个参数,并执行以下行:

ssh $STACK 'bash -l -c "./deploy_intermediate.sh $2 $3 $4"'
但是,我无法获得2美元、3美元和4美元来输出传递的参数。有没有办法在单引号内访问它们?执行上述行的最佳方式是什么

我真的很感激任何帮助


谢谢。

要传递参数,您必须写入:

ssh $STACK 'bash -l -c "./deploy_intermediate.sh '$2 $3 $4'"'
因此,您为扩展
$i
值让路。然而,我认为您可能只需运行以下命令即可获得相同的结果:

ssh $STACK "./deploy_intermediate.sh $2 $3 $4"
诀窍是:

ssh -i ~/.ssh/"$GIT_PRIVKEY" user@"$IP" "bash -s" < localpath/script.sh "$arg1" "$arg2"
ssh-i~/.ssh/“$GIT_PRIVKEY”用户@“$IP”bash-s”
但如果这些参数中有任何一个包含空格或shell元字符,则会产生令人惊讶的结果。@rici然后用双引号转义每个变量就足够了。类似于:
ssh。。。“/command\“$1\”“$2\”…”
“双引号”包含空格/元字符的每个文本和每个扩展:
“$var”
“$(command“$var”)”
“${.array[@]}”
“a&b”
。看,还有。