#! /bin/sh # run a command in each of several directories cmd="$1" shift case $# in 0) echo "Usage: $0 cmd dir ..." >&2 ; exit 2 ;; esac for d do if test ! -d $d then echo "$0: \`$d' is not a directory" >&2 exit 1 fi done here=`pwd` for d do echo "==== $d:" >&2 cd $here/$d eval $cmd if test $? -ne 0 then echo "*** $0 terminated" >&2 exit 1 fi echo done exit 0