Reputation: 43
I'm using this script to run a command within each subdirectory in the 'sites' directory, EXCLUDING the 'all' subdirectory. However, when I run this, the 'all' subdirectory is still being used, even though I use an if statement to exclude it.
for dir in ~/htdocs/drupal/drupal/sites/*
do
if [ $dir = "/local/users/drupadm/htdocs/drupal/drupal/all" ]
then
continue
fi
echo $dir
(cd $dir && /opt/webstack/php/5.2/bin/php /local/users/drupadm/drush/drush.php $1)
done
Bryan
Upvotes: 2
Views: 12733
Reputation: 33
Hi you need to do the following
if [ $dir == "/local/users/drupadm/htdocs/drupal/drupal/all" ]
Thanks
Upvotes: -1
Reputation: 6810
IFS=$'\n'
for dir in `find ~/htdocs/drupal/drupal/sites/ -maxdepth 1 -type d ! -name all -printf '%p\n'`
do
echo $dir
(cd $dir && /opt/webstack/php/5.2/bin/php /local/users/drupadm/drush/drush.php $1)
done
IFS=' '
Exclude that directory in the first place, use find!
It's invoked by
find dir_name [tests...]
Tests used by my command:
-maxdepth 1
Of immediate children...
-type d
... find directories ...
! -name all
... Not named 'all'.
Upvotes: 0
Reputation: 132
Try quoting the $dir, you will fine directories with spaces in their names kill you. You may also run scripts with -vx switches on the invocation to see what's read in and what's executed. bash -vx my script or set -vx whatever.
Upvotes: -1
Reputation: 362157
You left out the sites
sub-directory:
if [ "$dir" = /local/users/drupadm/htdocs/drupal/drupal/sites/all ]
Upvotes: 8