Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash : expression recursion level exceeded (error token is ...)

I'm writing a program that prints the username and the number of times that the user has logged in, or prints "Unknown user" otherwise.

My code is the following:

iden=$1
c='last | grep -w -c $iden'
if (( $c > 1 ))
then
    echo "$iden $c"
else
    echo "Unknown user"
fi

And I keep getting this error:

-bash: ((: last | grep -w -c 123: expression recursion level exceeded (error token is "c 123")

like image 840
Pedro Avatar asked Jun 03 '26 12:06

Pedro


1 Answers

To store the output of a command in a variable you need to say var=$(command). Hence, use:

c=$(last | grep -w -c "$iden")  # always good to quote the variables

instead of

c='last | grep -w -c $iden'

If you are learning Bash scripting, it is always handy to paste your code in ShellCheck to see the problems you may have.

like image 64
fedorqui 'SO stop harming' Avatar answered Jun 06 '26 07:06

fedorqui 'SO stop harming'



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!