我正在编写一个程序,打印用户名和用户登录次数,否则打印“未知用户”。
我的代码如下:
iden=$1
c='last | grep -w -c $iden'
if (( $c > 1 ))
then
echo "$iden $c"
else
echo "Unknown user"
fi
而且我一直收到这个错误:
-bash: ((: last | grep -w -c 123: expression recursion level exceeded (error token is "c 123")
最佳答案
要将命令的输出存储在变量中,您需要说 var=$(command)
。因此,使用:
c=$(last | grep -w -c "$iden") # always good to quote the variables
代替
c='last | grep -w -c $iden'
如果您正在学习 Bash 脚本,将您的代码粘贴到 ShellCheck 以查看您可能遇到的问题总是很方便。
关于linux - bash : expression recursion level exceeded (error token is . ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721707/