These are my very first steps with bash scripts and I have an issue.

I want to list all plugins and themes in the directory of the website, which have available updates:

1 #!/bin/bash
 3 #check for updates of plugins, themes and core version in a WordPress installations
 5 str1="available"
 6 str2="none"
 8 wp plugin list | grep available | awk '{print $1, $2, $3, $4}'
10 if [ "$str1" == "$str2" ]; then
11     echo "Updates available"
12     else
13         echo "No updates available"
14         fi
17 wp theme list | grep available | awk '{print $1, $2, $3, $4}'
19 if [ "$str1" == "$str2" ]; then
20 11     echo "Updates available"
21 12     else
22 13         echo "No updates available"
23 14         fi

However, if I execute the script, the following output appears:

No updates available updates_check: line 26: syntax error: unexpected end of file

I've tried to find a solution over the web. Can you please share how the script should be ended? Thank you!

1 Answer 1



One way is to do the counting of the available string in the third column via AWK:

wp plugin list | \
 awk 'BEGIN{N=0;} \
  ($3=="available"){N++; print $0;} \
  END{print(N>0)?"Plugin updates available: "N:"No plugin updates available";}'

where N is the number of available updates, in case you need the number, $0 is the whole row and $3 the third column.

Example output:

Foo-plugin    active  available       1.2.3
Plugin updates available: 1

Similar for themes.

WP-CLI and PHP/WordPress API

Another way is to do this via a PHP script, that includes the relevant WordPress API calls and run it like:

wp eval-file script.php

or as a custom WP-CLI command.

See e.g. my answer here and here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.