Answer the question
In order to leave comments, you need to log in
What is the error (let: =: syntax error: operand expected (error token is "="))?
Hello!
There is a script:
#!/bin/bash
echo "Введите своё имя:"
read user_name
let count = `grep $user_name /etc/passwd | wc -l`
if [ $count -gt 0 ];
then
echo "В файле /etc/passwd найдено $count совпадений!"
else
echo "Нет совпадений!"
fi
Answer the question
In order to leave comments, you need to log in
You have a space between count between = and between the actual value being assigned, resulting in count being empty.
And in the test statement you have [ $count -gt 0] with an empty variable, $count stands for [ -gt 0 ], which is what the syntax error reports.
When using the test statement, always quote variables, i.e.
[ "$count" -gt 0 ] or use the advanced test - , which is even better.
Be careful with spaces - where they are needed and where they are not needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question