我有以下内容:
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.
我在这里想念的是什么? 感谢任何帮助
答案 0 :(得分:3)
您使用的是$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)
,如
#!/bin/bash -i
# Expand aliases defined in the shell ~/.bashrc
shopt -s expand_aliases
得到相同的结果。