我想执行以下操作:
PASSWORD="mypassword"
RUNCOMMAND=$(cat <<EOF
echo $PASSWORD | sudo -S sudo echo "this is it babe"
EOF
)
Run Code Online (Sandbox Code Playgroud)
但this is it babe我得到的不是 ,而是以下结果:
mypassword | sudo -S sudo echo "this is it babe"
Run Code Online (Sandbox Code Playgroud)
我尝试过cat <<\EOF,cat <<'EOF'仍然没有运气。
有任何想法吗?
您将 aheredoc与 a混淆了pipeline。
cat <<EOF
some text, possibly with variables: ${HOME} / $(whoami)
EOF
Run Code Online (Sandbox Code Playgroud)
some text, possibly with variables: /home/attie / attie
Run Code Online (Sandbox Code Playgroud)
some text, possibly with variables: /home/attie / attie
Run Code Online (Sandbox Code Playgroud)
some text, possibly with variables: ${HOME} / $(whoami)
Run Code Online (Sandbox Code Playgroud)
"):cat <<"EOF"
some text, possibly with variables: ${HOME} / $(whoami)
EOF
Run Code Online (Sandbox Code Playgroud)
some text, possibly with variables: /home/attie / attie
Run Code Online (Sandbox Code Playgroud)
'):some text, possibly with variables: ${HOME} / $(whoami)
Run Code Online (Sandbox Code Playgroud)
some text, possibly with variables: ${HOME} / $(whoami)
Run Code Online (Sandbox Code Playgroud)
${...}扩展环境变量
$(...)运行一个命令,并替换它的stdout
看起来您还试图输入密码sudo- 这不起作用,因为 sudo 将重新启动终端以获取您的密码,然后再将其传递stdin给最终应用程序。
| 归档时间: |
|
| 查看次数: |
7075 次 |
| 最近记录: |