1. 程式人生 > >Shell中執行sudo命令

Shell中執行sudo命令

使用 echo "passwd"|sudo -S command

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.

即-S使得sudo從標準輸入讀取密碼而非終端

例如 在shell中執行關機命令

#!/bin/bash

echo "passwd"|sudo -S shutdown -P now