linux - bash : expression recursion level exceeded (error token is . ..)

标签 linux bash shell unix

我正在编写一个程序,打印用户名和用户登录次数,否则打印“未知用户”。

我的代码如下:

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/

相关文章:

linux - 如何检查服务和服务器是否可用?

C: 在 Linux 上可靠地导致 `double free or corruption`

java - 何时为映射 servlet 加载 web.xml 文件?

linux - fatal error : xmlsec/xmlsec. h:没有这样的文件或目录

python - 在cygwin错误上安装tensorflow

php - 在 Ubuntu 终端上未检测到 Composer 供应商/bin 文件

linux - 启动脚本总是在 ubuntu 9.10 服务器版上崩溃

linux - 从不同文件夹中提取嵌套的不同类型的文件

bash 错误 "date: invalid date ` 24/06/2013 21 :2 2'" with Debian but not with RHEL?

android - 在 Android 中以编程方式执行 shell 命令