2017-07-06 84 views

回答

3

您正在使用$user,但需要$USER。像,

count=$(who | grep $USER | wc -l) 
echo "$USER is logged on $count times." 

我得到

efrisch is logged on 4 times. 

另一種選擇是printf

printf "%s is logged on %s times.\n" $USER $(who | grep $USER | wc -l) 

了相同的結果。