1

I have a bash script like this:

vartest=(`/usr/local/pgsql/bin/psql -h 10.0.1.143 -t -p 6432 -d gpperfmon -c "select delete_oldest_db_test();"`)
echo ${vartest[2]}


what_to_delete=${vartest[2]}

if ["$what_to_delete" == "Nothing"]; then
echo "Nothing to delete"
else
dropdb -h 10.0.1.143 -p 6432 -U postgres ${vartest[0]}

fi

But when I run it I get this:

line 7: [Nothing: command not found

I've tried to compare using quotes, double quotes, no quotes at all, and nothing seems to work.. The issue is in this line:

  if ["$what_to_delete" == "Nothing"]; then

Thanks

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Matias
  • 539
  • 5
  • 28

1 Answers1

0

It was a syntax issue, thanks Gilles for sharing the link to check script.

I didn't have a space between the braket and the double quote..

it was a matter of adding the missing space before and after:

if [ "$what_to_delete" = "Nothing" ]; then
Matias
  • 539
  • 5
  • 28
  • 1
    While using bash, you should prefer `[[ ]]` way. [[ is a bash keyword similar to (but more powerful than) the [ command. See and . Unless you're writing for POSIX sh, we recommend [[. – Gilles Quénot Dec 16 '22 at 12:00