Don't use '$mdadm', just 'mdadm'. And --stop all arrays when finished.
Needs work for other levels etc. Signed-off-by: Neil Brown <neilb@suse.de>