[英]How to pass a long string(with new lines) variable as enviroment to ssh command
KEY=$(cat ~/.ssh/id_rsa.pub)
ssh root@127.0.0.1 KEY="$KEY" echo "hi"
它將失敗並顯示如下錯誤:
bash: AAAAB3NzaC1yc2EAAAADAQABAAABAQDJ65FHdb8FyD...tpFnRUSZ: No such file or directory
我該如何解決?
假設使用 bash:
對於更通用的情況,輸入可能包含任意字符,包括引號,請考慮使用(特定於基本的) ${var@A}
創建分配:
ssh root@localhost ${KEY@A} echo 'hi'
更新 1:bash(4.4 版)手冊頁:在“@A”(和其他)操作上:
${parameter@operator} Parameter transformation. The expansion is either a transformation of the value of parameter or information about parameter itself, depending on the value of operator. Each operator is a single letter: Q The expansion is a string that is the value of parameter quoted in a format that can be reused as input. E The expansion is a string that is the value of parameter with backslash escape sequences expanded as with the $'...' quoting mechansim. P The expansion is a string that is the result of expanding the value of parameter as if it were a prompt string (see PROMPTING below). A The expansion is a string in the form of an assignment statement or declare command that, if evaluated, will recreate parameter with its attributes and value. a The expansion is a string consisting of flag values representing parameter's attributes.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.