1. 管道
上一条命令的stdout,作为下一条命令的stdin:
echo pwd123 | sudo -S rm test
2. << 和 EOF
<< 结合 EOF ,后续输入作为子命令或子Shell的输入,直到遇到EOF为止,并返回到主Shell,这里把要输入的密码夹在<< 和 EOF当中,作为命令的输入
sudo -S rm test <<
pwd123
EOF
3. 参数 -S
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.
The password must be followed by a newline character.