我從服務器(Ubuntu 12.04)獲取主機名和IP地址,如here解釋。它工作正常。過了一段時間,我意識到服務器在離線狀態下返回「(none)」作爲主機名。現在我試圖通過比較主機名和「(none)」來消除這個錯誤。我試過所有這些(*),但它們都不起作用:
-- Getting hostname here
hostname=$(grep "host-name" /var/lib/dhcp/dhclient.${interface}.leases | tail -n1 | cut -d"\"" -f2 | cut -d"." -f1)
-- Trying to compare it with "(none)"
* if [ "$hostname" != "(none)" ] then ... else ... fi
* if [[ $hostname != "(none)" ]] then ... else ... fi
* nouser="(none)" if [ "$hostname" != "$nouser" ] then ... else ... fi
我在做什麼錯? Thx尋求幫助。
'if [「$ hostname」!=「(none)」];那麼... else ... fi'注意'''''''''''' – maverik
之後的符號我也試過了。它沒有奏效。還有,如果[]聲明沒有結束「;」在代碼中,它工作沒有問題。 –
你看到了什麼結果? – armandino