SSH定界符:bash提示符 [英] SSH heredoc: bash prompt
问题描述
我试图写一个shell脚本SSHS到服务器,然后提示用户输入一个文件/文件夹。
SSH $服务器16;< EOF
CD下载/
阅读-e -p输入该文件的路径:FILEPATH
回声$ FILEPATH
EVAL FILEPATH =$ FILEPATH回声下载$ FILEPATH至$客户端
EOF
我使用的定界符,而不是双引号的SSH后,因为我的shell脚本是相当大的,以执行这些命令,我不希望被转义每一个双引号。
当我使用双引号,提示工作得很好。然而,现在我使用定界符,提示不再有效。
我能做些什么,以获得及时定界符工作?如果没有,有没有什么办法我布置我的脚本,这样的提示确实没有包裹在双引号中的一切和逃避,像这样的工作:
SSH $ SERVER
CD下载/
阅读-e -p \\中输入文件路径:\\FILEPATH
回声$ FILEPATH
EVAL FILEPATH = \\$ FILEPATH \\回声\\下载$ FILEPATH至$ CLIENT \\
出口
如果你不需要任何来自客户端的变量,为什么不尝试 - 和的ssh -t
可能是有用的。
导出客户端=我CMDS = $(猫<< CMD
CD下载/
阅读-e -p输入该文件的路径:FILEPATH
回声\\ $ FILEPATH
EVAL FILEPATH =\\ $ FILEPATH回声下载\\ $ FILEPATH至$客户端
CMD
)SSH本地主机-t$ CMDS
请注意,如果你用双引号唯一的问题是逃跑了,你不打算
使用
单引号在你的脚本,那么你可以UST做到这一点:
的ssh -t $ SERVER
#脚本,转义。
如果你想获得一个本地定义变量#,
回声客户端是'$ CLIENT'。
I am attempting to write a shell script which SSHs into a server and then prompts the user to enter a file/folder.
ssh $SERVER <<EOF
cd downloads/
read -e -p "Enter the path to the file: " FILEPATH
echo $FILEPATH
eval FILEPATH="$FILEPATH"
echo "Downloading $FILEPATH to $CLIENT"
EOF
I am using heredoc instead of double quotes after the SSH to execute these commands because my shell script is rather large and I don't want to be escaping every double quote.
When I was using double quotes, the prompt worked fine. However, now that I am using heredoc, the prompt no longer works.
What can I do to get the prompt to work with heredoc? And if not, is there any way I layout my script so that the prompt does work without wrapping everything in double quotes and escaping, like so:
ssh $SERVER "
cd downloads/
read -e -p \"Enter the path to the file: \" FILEPATH
echo $FILEPATH
eval FILEPATH=\"$FILEPATH\"
echo \"Downloading $FILEPATH to $CLIENT\"
exit
"
If you don't need any variables from the client, why not try - and ssh -t
might be useful.
export CLIENT=me
CMDS=$(cat <<CMD
cd downloads/
read -e -p "Enter the path to the file: " FILEPATH
echo \$FILEPATH
eval FILEPATH="\$FILEPATH"
echo "Downloading \$FILEPATH to $CLIENT"
CMD
)
ssh localhost -t "$CMDS"
Note that if your only issue with double-quotes is escaping, and you do not plan on
using '
single quotes in your script, then you can ust do this:
ssh -t $SERVER '
# your script, unescaped.
# if you want access to a locally defined variable,
echo "CLIENT is '$CLIENT'."
'
这篇关于SSH定界符:bash提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!