I try to compare in a Script two different version numbers of Drupal via drush status. The result should be printed out in a if-else. I made a minimal example:

# put paths in vars

# get the drupal version line from drupal status output
test=$(drush status | grep "Drupal version")
live=$(drush status | grep "Drupal version")

# count chars in output
wc -c <<< $live
wc -c <<< $test

# print variables
echo $live
echo $test

# compare
if [ "$test" != "$live" ]
    echo "not equal"
    echo "equal"

Strangely this is the output:

Drupal version : 9.5.0
Drupal version : 9.5.0
not equal

The difference in characters is the explanation, but why are they different? On one side the string has not so much chars, on the other side they are different length. Why is that so, and how can i fix this? I suspect the substitution within the shells $() syntax.

1 Answer 1


The standard output of Drush is for humans.

For scripts use the Drush output options to select the field and output a string value:

drush status --fields=drupal-version --format=string

or shorter with --field=FIELD to select just one field, and force format to string.

drush status --field=drupal-version

See drush help status.

  • Perfect that does the trick, thank you very much! But do you know why the grepped output is diffrent, seems wired...
    – gzwg
    Jan 13 at 13:53
  • 2
    I think different Drupal/Drush version have different whitespaces. The human readable output is not an API.
    – 4uk4
    Jan 13 at 13:54
  • Thanks for the explanation and the hint for fixing!
    – gzwg
    Jan 13 at 14:00

Your Answer

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

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