Yes, changing the working directory back and forth is cumbersome and not really what you would like to do as it can lead to extremely weird situations in more complex scripts, unless you are careful.
The usual method for changing the working directory for a simple command is to put the
cd and to invocation of the command in a sub-shell. The working directory will be changed for the sub-shell but the change is not carried over to the rest of the script as the sub-shell is executing in its own environment.
mycommand inside all directories in the current working directory:
for d in *; do
if [ -d "$d" ]; then # or: if test -d "$d"; then
( cd "$d" && mycommand )
or in your case, with known directories
for d in a b; do
( cd "$d" && dsmmigrate * & )
I don't know the
dsmmigrate tool, so I can't say whether running it this way is right or not.
EDIT: It turns out that the
dsmmigrate tool has a
$ dsmmigrate -Recursive /path