Any idea how can I tell the script/drush to stop when the previous command failed?


echo "Disabling parallel config..."
drush vset parallel_enabled 0 

drush vset preprocess_css 0
drush vset preprocess_js 0
drush cc all 

# Disable Mobile theme  
echo "Disabling Mobile theme..."
drush dis --yes mobiletheme

# Disable Zen theme  
echo "Disabling Zen..."
drush dis --yes zen 

# Running the site to offline mode  
echo "Running site in offline mode..."
drush vset --yes site_offline 1 

# Deleting node revisions
echo "Deleting node revisions..."
drush delete-revisions -y

echo "Clearing all the caches..."
drush cc all 

# Rename duplicate files
echo "Renaming duplicate files..."
drush rename-duplicate-files

drush pm-uninstall publication_date -y
drush pm-uninstall date -y
drush pm-uninstall custom_pagers -y 
drush pm-uninstall custom_breadcrumbs -y

I want something like this:

echo "Disabling parallel config..."
drush vset parallel_enabled 0 
if [ ! success ]; then
  echo "The command failed to execute."
  • Not sure who voted to close, but I disagree with that. The question may not be directly related to Drupal, but it is a Drupal activity and I can see this question helping future visitors.
    – mpdonadio
    Aug 30, 2012 at 12:34

1 Answer 1


Checkout the run_cmd function in this file: base_functions, which wraps any command and terminates the script if it fails.

You should also be able to do something like:

drush cc all || exit;

where exit will only run if the previous command fails, and you could replace exit with a call to a function that outputs a more meaningful error message. You may also add a number between 1 and 255 after exit to have your script emit an exit status that can be used further using $? in any other script calling this one.

  • 1
    Hi Letharion..the drush always return 0 status no matter what. Like I run the drush updb -y outside the Drupal and it complains that I cannot run drush updb -y coz Command updatedb needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command. so I assumed that the status is not equal to zero since the command failed. Any idea?
    – user8012
    Aug 31, 2012 at 3:17
  • That is not the case for me. drush updb; echo $? yields 1 when invalid, while drush help; echo $? always yields 0. This also triggers the expected response when using either && or || for me. Using drush 4.5 and bash 4.2.
    – Letharion
    Aug 31, 2012 at 8:26

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.