我想运行一个简单的for循环来检查并显示几个硬盘的像这样的温度:如何运行一个用于在bash命令行根上环
for drive in a b c d e f g; do hddtemp "/dev/sd$drive"; done
该作品很好,如果我su根,但我想只能在命令行运行它或其他循环类型的单行命令,如果可能的话,可能需要sudo。
如果我尝试
sudo for drive in a b c d e f g; do hddtemp "/dev/sd$drive"; done;
我得到这个错误:
bash: syntax error near unexpected token `do'
同样的错误,如果我省略"
(双引号)最终;
(分号)
内附上述命令给出这个结果:
sudo: for drive in a b c d e f g; do hddtemp /dev/sdg; done: command not found
围在背蜱
sudo "`for drive in a b c d e f g; do hddtemp "/dev/sd$drive"; done`"
命令(`
)给出了驱动器号的每个实例的错误/指定规格:
/dev/sda: open: Permission denied followed by sudo: : command not found
是否有可能用于(或其他循环运行)命令作为命令行单行sudo'ing或以其他方式在bash中使用我的根凭证?
Ubuntu Linux操作系统16.04LTS/GNU的bash 46年3月4日(1)
更好地利用'的/ dev/SD?' –
看起来短而像它会Ë xtend到这种循环运行sudo命令最为普遍,谢谢。 –