0

I am unsure what is causing this error. Script continues to run and enters the "if" statement without issues.

"./test.sh: line 79: [: too many arguments"

if [ grep -Fq "variable=00000000000" /home/me/test.txt ] ; then             #line 79
             ........
             ........
else
             echo "hi"
fi
presish
  • 3
  • 1

2 Answers2

0

Simply use :

if grep -Fq "variable=00000000000" /home/me/test.txt; then
[...]

or

grep -Fq "variable=00000000000" /home/me/test.txt && echo 'true'

Explanations

Every command have a return code that you can display with :

true
echo $? # return 0, true in bash
false
echo $? # return 1: false in bash

It's named boolean logic

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0

[ ... ] is not part of the syntax of an if statement. [ is a command name, that requires a final argument of ] to simulate the look of syntax. Drop them if you want to run a different command whose exit status if should check.

if grep -Fq "..." /honme/me/test.txt; then
chepner
  • 497,756
  • 71
  • 530
  • 681