1>/dev/null 2>&1 為何呢?

0 = standard input (stdin)
1 = standard output (stdout)
2 = standard error (stderr)

意指將stderr轉向為stdout,而一起丟進/dev/null裡,就不會顯示文字在螢幕上。

 

 

程式碼如下:

#!/bin/bash

cmd='ipmitool -U admin -P admin -H 192.168.1.1 chassis power status'

if $cmd 1>/dev/null 2>&1; then
    echo "Command is Yes."
else
    echo "Command is No."
fi

arrow
arrow
    全站熱搜

    dreamtails 發表在 痞客邦 留言(0) 人氣()