1
我有以下幾點:腳本shell:說了多少次,用戶登錄
count=$(who | grep $user | wc -l)
echo "$user is logged on $count times."
but it gives me the following output:
is logged on 0 times.
我缺少什麼嗎? 感謝任何幫助
我有以下幾點:腳本shell:說了多少次,用戶登錄
count=$(who | grep $user | wc -l)
echo "$user is logged on $count times."
but it gives me the following output:
is logged on 0 times.
我缺少什麼嗎? 感謝任何幫助
您正在使用$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)
了相同的結果。