diff --git a/tests/sys/geom/class/concat/1_test.sh b/tests/sys/geom/class/concat/1_test.sh
--- a/tests/sys/geom/class/concat/1_test.sh
+++ b/tests/sys/geom/class/concat/1_test.sh
@@ -4,9 +4,9 @@
 
 echo '1..1'
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 gconcat create $name /dev/$us0 /dev/$us1 /dev/$us2 || exit 1
 devwait
diff --git a/tests/sys/geom/class/concat/2_test.sh b/tests/sys/geom/class/concat/2_test.sh
--- a/tests/sys/geom/class/concat/2_test.sh
+++ b/tests/sys/geom/class/concat/2_test.sh
@@ -8,9 +8,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 dd if=/dev/random of=${src} bs=1m count=$tsize >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/concat/append1.sh b/tests/sys/geom/class/concat/append1.sh
--- a/tests/sys/geom/class/concat/append1.sh
+++ b/tests/sys/geom/class/concat/append1.sh
@@ -22,9 +22,9 @@
 
 echo '1..3'
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 1M) || exit 1
-us2=$(attach_md -t malloc -s 1M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 1M || exit 1
+attach_md us2 -t malloc -s 1M || exit 1
 
 gconcat create $name /dev/$us0 /dev/$us1 || exit 1
 devwait
diff --git a/tests/sys/geom/class/concat/append2.sh b/tests/sys/geom/class/concat/append2.sh
--- a/tests/sys/geom/class/concat/append2.sh
+++ b/tests/sys/geom/class/concat/append2.sh
@@ -31,9 +31,9 @@
 f3=$(mktemp) || exit 1
 truncate -s $((1024 * 1024 + $ss)) $f3
 
-us0=$(attach_md -f $f1 -S $ss) || exit 1
-us1=$(attach_md -f $f2 -S $ss) || exit 1
-us2=$(attach_md -f $f3 -S $ss) || exit 1
+attach_md us0 -f $f1 -S $ss || exit 1
+attach_md us1 -f $f2 -S $ss || exit 1
+attach_md us2 -f $f3 -S $ss || exit 1
 
 gconcat label $name /dev/$us0 /dev/$us1 || exit 1
 devwait
@@ -57,9 +57,9 @@
 
 # Re-create the providers and verify that the concat device comes
 # back and that the data is still there.
-us0=$(attach_md -f $f1 -S $ss) || exit 1
-us1=$(attach_md -f $f2 -S $ss) || exit 1
-us2=$(attach_md -f $f3 -S $ss) || exit 1
+attach_md us0 -f $f1 -S $ss || exit 1
+attach_md us1 -f $f2 -S $ss || exit 1
+attach_md us2 -f $f3 -S $ss || exit 1
 
 devwait
 
diff --git a/tests/sys/geom/class/eli/attach_test.sh b/tests/sys/geom/class/eli/attach_test.sh
--- a/tests/sys/geom/class/eli/attach_test.sh
+++ b/tests/sys/geom/class/eli/attach_test.sh
@@ -12,7 +12,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
@@ -50,7 +50,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	atf_check geli init -B none -P -K keyfile ${md}
@@ -78,9 +78,9 @@
 	geli_test_setup
 
 	sectors=100
-	md0=$(attach_md -t malloc -s `expr $sectors + 1`)
-	md1=$(attach_md -t malloc -s `expr $sectors + 1`)
-	md2=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md0 -t malloc -s `expr $sectors + 1`
+	attach_md md1 -t malloc -s `expr $sectors + 1`
+	attach_md md2 -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	atf_check geli init -B none -P -K keyfile ${md0}
@@ -108,7 +108,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	atf_check geli init -B none -P -K keyfile ${md}
diff --git a/tests/sys/geom/class/eli/conf.sh b/tests/sys/geom/class/eli/conf.sh
--- a/tests/sys/geom/class/eli/conf.sh
+++ b/tests/sys/geom/class/eli/conf.sh
@@ -6,12 +6,14 @@
 
 attach_md()
 {
-	local test_md
+	local _md
+	local rv=$1
+	shift
 
 	[ -c /dev/mdctl ] || atf_skip "no /dev/mdctl to create md devices"
-	test_md=$(mdconfig -a "$@") || atf_fail "failed to allocate md(4)"
-	echo $test_md >> $TEST_MDS_FILE || exit
-	echo $test_md
+	_md=$(mdconfig -a "$@") || atf_fail "failed to allocate md(4)"
+	echo $_md >> $TEST_MDS_FILE || exit
+	eval "${rv}='${_md}'"
 }
 
 # Execute `func` for each combination of cipher, sectorsize, and hmac algo
@@ -30,9 +32,9 @@
 		# Use a file-backed md(4) device, so we can deliberatly corrupt
 		# it without detaching the geli device first.
 		truncate -s $bytes backing_file
-		md=$(attach_md -t vnode -f backing_file)
+		attach_md md -t vnode -f backing_file
 	else
-		md=$(attach_md -t malloc -s $bytes)
+		attach_md md -t malloc -s $bytes
 	fi
 
 	for cipher in aes-xts:128 aes-xts:256 \
@@ -58,7 +60,7 @@
 
 	# geli needs 512B for the label.
 	bytes=`expr $MAX_SECSIZE \* $sectors + 512`b
-	md=$(attach_md -t malloc -s $bytes)
+	attach_md md -t malloc -s $bytes
 	for cipher in aes-xts:128 aes-xts:256 \
 	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
 	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
diff --git a/tests/sys/geom/class/eli/configure_test.sh b/tests/sys/geom/class/eli/configure_test.sh
--- a/tests/sys/geom/class/eli/configure_test.sh
+++ b/tests/sys/geom/class/eli/configure_test.sh
@@ -12,7 +12,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check geli init -B none -P -K /dev/null ${md}
 
diff --git a/tests/sys/geom/class/eli/delkey_test.sh b/tests/sys/geom/class/eli/delkey_test.sh
--- a/tests/sys/geom/class/eli/delkey_test.sh
+++ b/tests/sys/geom/class/eli/delkey_test.sh
@@ -13,7 +13,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
 	atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
@@ -91,7 +91,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	atf_check geli init -B none -P -K keyfile ${md}
diff --git a/tests/sys/geom/class/eli/detach_test.sh b/tests/sys/geom/class/eli/detach_test.sh
--- a/tests/sys/geom/class/eli/detach_test.sh
+++ b/tests/sys/geom/class/eli/detach_test.sh
@@ -12,7 +12,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
diff --git a/tests/sys/geom/class/eli/init_test.sh b/tests/sys/geom/class/eli/init_test.sh
--- a/tests/sys/geom/class/eli/init_test.sh
+++ b/tests/sys/geom/class/eli/init_test.sh
@@ -68,7 +68,7 @@
 
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
-	md=$(attach_md -t malloc -s $sectors)
+	attach_md md -t malloc -s $sectors
 
 	# -B none
 	rm -f /var/backups/${md}.eli
@@ -118,7 +118,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=keyfile0 bs=512 count=16 status=none
 	atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
@@ -303,7 +303,7 @@
 {
 	geli_test_setup
 
-	md=$(attach_md -t malloc -s 1024k)
+	attach_md md -t malloc -s 1024k
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	for spec in aes:0:AES-XTS:128 aes:128:AES-XTS:128 aes:256:AES-XTS:256 \
@@ -334,7 +334,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
@@ -357,7 +357,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check -s not-exit:0 -e match:"No key components given" \
 		geli init -B none -P ${md}
diff --git a/tests/sys/geom/class/eli/kill_test.sh b/tests/sys/geom/class/eli/kill_test.sh
--- a/tests/sys/geom/class/eli/kill_test.sh
+++ b/tests/sys/geom/class/eli/kill_test.sh
@@ -12,7 +12,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
 	atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
@@ -76,7 +76,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	atf_check geli init -B none -P -K keyfile ${md}
diff --git a/tests/sys/geom/class/eli/misc_test.sh b/tests/sys/geom/class/eli/misc_test.sh
--- a/tests/sys/geom/class/eli/misc_test.sh
+++ b/tests/sys/geom/class/eli/misc_test.sh
@@ -37,7 +37,7 @@
 {
 	geli_test_setup
 
-	md=$(attach_md -s1m)
+	attach_md md -s1m
 	atf_check geli onetime /dev/${md}
 	md_secsize=$(diskinfo ${md} | cut -wf 2)
 	md_stripesize=$(diskinfo ${md} | cut -wf 5)
@@ -103,7 +103,7 @@
 		atf_skip "$error_message"
 	fi
 
-	md=$(attach_md -s1m)
+	attach_md md -s1m
 	# If the underlying device has no physical path, then geli should not
 	# create one.
 	atf_check -o empty -e ignore diskinfo -p $md
diff --git a/tests/sys/geom/class/eli/onetime_test.sh b/tests/sys/geom/class/eli/onetime_test.sh
--- a/tests/sys/geom/class/eli/onetime_test.sh
+++ b/tests/sys/geom/class/eli/onetime_test.sh
@@ -103,7 +103,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s $sectors)
+	attach_md md -t malloc -s $sectors
 
 	atf_check geli onetime -d ${md}
 	if [ ! -c /dev/${md}.eli ]; then
@@ -147,7 +147,7 @@
 	ealgo=${cipher%%:*}
 	keylen=${cipher##*:}
 
-	md=$(attach_md -t malloc -s 100k)
+	attach_md md -t malloc -s 100k
 
 	atf_check -s exit:0 -o ignore -e ignore \
 		geli onetime -e null -s ${secsize} ${md}
diff --git a/tests/sys/geom/class/eli/online_resize_test.sh b/tests/sys/geom/class/eli/online_resize_test.sh
--- a/tests/sys/geom/class/eli/online_resize_test.sh
+++ b/tests/sys/geom/class/eli/online_resize_test.sh
@@ -42,7 +42,7 @@
 			psize30="33776997205278720"
 		fi
 
-		md=$(attach_md -t malloc -s40${prefix})
+		attach_md md -t malloc -s40${prefix}
 
 		# Initialise
 		atf_check -s exit:0 -o ignore gpart create -s GPT ${md}
diff --git a/tests/sys/geom/class/eli/resize_test.sh b/tests/sys/geom/class/eli/resize_test.sh
--- a/tests/sys/geom/class/eli/resize_test.sh
+++ b/tests/sys/geom/class/eli/resize_test.sh
@@ -15,7 +15,7 @@
 	BLK=512
 	BLKS_PER_MB=2048
 
-	md=$(attach_md -t malloc -s40m)
+	attach_md md -t malloc -s40m
 
 	# Initialise
 	atf_check -s exit:0 -o ignore gpart create -s BSD ${md}
diff --git a/tests/sys/geom/class/eli/setkey_test.sh b/tests/sys/geom/class/eli/setkey_test.sh
--- a/tests/sys/geom/class/eli/setkey_test.sh
+++ b/tests/sys/geom/class/eli/setkey_test.sh
@@ -13,7 +13,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=rnd bs=512 count=${sectors} status=none
 	hash1=`dd if=rnd bs=512 count=${sectors} status=none | md5`
@@ -103,7 +103,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 
 	atf_check dd if=/dev/random of=rnd bs=512 count=${sectors} status=none
 	hash1=`dd if=rnd bs=512 count=${sectors} status=none | md5`
@@ -161,7 +161,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
 
 	atf_check geli init -B none -P -K keyfile ${md}
@@ -186,7 +186,7 @@
 	geli_test_setup
 
 	sectors=100
-	md=$(attach_md -t malloc -s `expr $sectors + 1`)
+	attach_md md -t malloc -s `expr $sectors + 1`
 	atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
 	atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
 
diff --git a/tests/sys/geom/class/geom_subr.sh b/tests/sys/geom/class/geom_subr.sh
--- a/tests/sys/geom/class/geom_subr.sh
+++ b/tests/sys/geom/class/geom_subr.sh
@@ -14,12 +14,14 @@
 
 attach_md()
 {
-	local test_md
+	local _md
+	local rv=$1
+	shift
 
 	[ -c /dev/mdctl ] || atf_skip "no /dev/mdctl to create md devices"
-	test_md=$(mdconfig -a "$@") || exit
-	echo $test_md >> $TEST_MDS_FILE || exit
-	echo $test_md
+	_md=$(mdconfig -a "$@") || exit
+	echo $_md >> $TEST_MDS_FILE || exit
+	eval "${rv}='${_md}'"
 }
 
 detach_md()
diff --git a/tests/sys/geom/class/mirror/10_test.sh b/tests/sys/geom/class/mirror/10_test.sh
--- a/tests/sys/geom/class/mirror/10_test.sh
+++ b/tests/sys/geom/class/mirror/10_test.sh
@@ -16,8 +16,8 @@
 dd if=/dev/random of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
 dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
 
-us0=$(attach_md -t vnode -f $m1)
-us1=$(attach_md -t vnode -f $m2)
+attach_md us0 -t vnode -f $m1
+attach_md us1 -t vnode -f $m2
 
 gmirror label $name /dev/$us0
 gmirror insert $name /dev/$us1
@@ -52,10 +52,10 @@
 # Force a retaste of the disconnected component.
 if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
 	detach_md $us1
-	us1=$(attach_md -t vnode -f $m2)
+	attach_md us1 -t vnode -f $m2
 else
 	detach_md $us0
-	us0=$(attach_md -t vnode -f $m1)
+	attach_md us0 -t vnode -f $m1
 fi
 
 # Make sure that the component wasn't re-added to the gmirror.
diff --git a/tests/sys/geom/class/mirror/11_test.sh b/tests/sys/geom/class/mirror/11_test.sh
--- a/tests/sys/geom/class/mirror/11_test.sh
+++ b/tests/sys/geom/class/mirror/11_test.sh
@@ -16,8 +16,8 @@
 dd if=/dev/random of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
 dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
 
-us0=$(attach_md -t vnode -f $m1)
-us1=$(attach_md -t vnode -f $m2)
+attach_md us0 -t vnode -f $m1
+attach_md us1 -t vnode -f $m2
 
 gmirror label $name /dev/$us0
 gmirror insert $name /dev/$us1
@@ -65,10 +65,10 @@
 # Force a retaste of the disconnected component.
 if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
 	detach_md $us1
-	us1=$(attach_md -t vnode -f $m2)
+	attach_md us1 -t vnode -f $m2
 else
 	detach_md $us0
-	us0=$(attach_md -t vnode -f $m1)
+	attach_md us0 -t vnode -f $m1
 fi
 
 # Make sure that the retaste caused the mirror to automatically be re-added.
diff --git a/tests/sys/geom/class/mirror/12_test.sh b/tests/sys/geom/class/mirror/12_test.sh
--- a/tests/sys/geom/class/mirror/12_test.sh
+++ b/tests/sys/geom/class/mirror/12_test.sh
@@ -16,8 +16,8 @@
 dd if=/dev/zero of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
 dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
 
-us0=$(attach_md -t vnode -f $m1)
-us1=$(attach_md -t vnode -f $m2)
+attach_md us0 -t vnode -f $m1
+attach_md us1 -t vnode -f $m2
 
 gmirror label $name /dev/$us0 /dev/$us1
 devwait
@@ -51,10 +51,10 @@
 # Force a retaste of the disconnected component.
 if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
 	detach_md $us1
-	us1=$(attach_md -t vnode -f $m2)
+	attach_md us1 -t vnode -f $m2
 else
 	detach_md $us0
-	us0=$(attach_md -t vnode -f $m1)
+	attach_md us0 -t vnode -f $m1
 fi
 
 # Make sure that the component wasn't re-added to the gmirror.
diff --git a/tests/sys/geom/class/mirror/13_test.sh b/tests/sys/geom/class/mirror/13_test.sh
--- a/tests/sys/geom/class/mirror/13_test.sh
+++ b/tests/sys/geom/class/mirror/13_test.sh
@@ -16,8 +16,8 @@
 dd if=/dev/random of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
 dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
 
-us0=$(attach_md -t vnode -f $m1)
-us1=$(attach_md -t vnode -f $m2)
+attach_md us0 -t vnode -f $m1
+attach_md us1 -t vnode -f $m2
 
 gmirror label $name /dev/$us0 /dev/$us1
 devwait
@@ -62,10 +62,10 @@
 # Force a retaste of the disconnected component.
 if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
 	detach_md $us1
-	us1=$(attach_md -t vnode -f $m2)
+	attach_md us1 -t vnode -f $m2
 else
 	detach_md $us0
-	us0=$(attach_md -t vnode -f $m1)
+	attach_md us0 -t vnode -f $m1
 fi
 
 # Make sure that the retaste caused the mirror to automatically be re-added.
diff --git a/tests/sys/geom/class/mirror/1_test.sh b/tests/sys/geom/class/mirror/1_test.sh
--- a/tests/sys/geom/class/mirror/1_test.sh
+++ b/tests/sys/geom/class/mirror/1_test.sh
@@ -4,9 +4,9 @@
 
 echo "1..1"
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 gmirror label $name /dev/$us0 /dev/$us1 /dev/$us2 || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/2_test.sh b/tests/sys/geom/class/mirror/2_test.sh
--- a/tests/sys/geom/class/mirror/2_test.sh
+++ b/tests/sys/geom/class/mirror/2_test.sh
@@ -13,9 +13,9 @@
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us1=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us2=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
+attach_md us0 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us1 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us2 -t malloc -s `expr $nblocks1 + 1` || exit 1
 
 gmirror label -b $balance $name /dev/${us0} /dev/${us1} /dev/${us2} || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/3_test.sh b/tests/sys/geom/class/mirror/3_test.sh
--- a/tests/sys/geom/class/mirror/3_test.sh
+++ b/tests/sys/geom/class/mirror/3_test.sh
@@ -13,9 +13,9 @@
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us1=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us2=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
+attach_md us0 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us1 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us2 -t malloc -s `expr $nblocks1 + 1` || exit 1
 
 gmirror label -b $balance $name /dev/${us0} /dev/${us1} /dev/${us2} || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/4_test.sh b/tests/sys/geom/class/mirror/4_test.sh
--- a/tests/sys/geom/class/mirror/4_test.sh
+++ b/tests/sys/geom/class/mirror/4_test.sh
@@ -13,9 +13,9 @@
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us1=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us2=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
+attach_md us0 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us1 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us2 -t malloc -s `expr $nblocks1 + 1` || exit 1
 
 gmirror label -b $balance $name /dev/${us0} /dev/${us1} /dev/${us2} || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/5_test.sh b/tests/sys/geom/class/mirror/5_test.sh
--- a/tests/sys/geom/class/mirror/5_test.sh
+++ b/tests/sys/geom/class/mirror/5_test.sh
@@ -13,9 +13,9 @@
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us1=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us2=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
+attach_md us0 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us1 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us2 -t malloc -s `expr $nblocks1 + 1` || exit 1
 
 gmirror label -b $balance -s `expr $ddbs / 2` $name /dev/${us0} /dev/${us1} /dev/${us2} || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/6_test.sh b/tests/sys/geom/class/mirror/6_test.sh
--- a/tests/sys/geom/class/mirror/6_test.sh
+++ b/tests/sys/geom/class/mirror/6_test.sh
@@ -13,9 +13,9 @@
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us1=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us2=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
+attach_md us0 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us1 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us2 -t malloc -s `expr $nblocks1 + 1` || exit 1
 
 gmirror label -b $balance -s `expr $ddbs / 2` $name /dev/${us0} /dev/${us1} || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/7_test.sh b/tests/sys/geom/class/mirror/7_test.sh
--- a/tests/sys/geom/class/mirror/7_test.sh
+++ b/tests/sys/geom/class/mirror/7_test.sh
@@ -13,9 +13,9 @@
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us1=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
-us2=$(attach_md -t malloc -s `expr $nblocks1 + 1`) || exit 1
+attach_md us0 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us1 -t malloc -s `expr $nblocks1 + 1` || exit 1
+attach_md us2 -t malloc -s `expr $nblocks1 + 1` || exit 1
 
 gmirror label -b $balance $name /dev/${us0} /dev/${us1} /dev/${us2} || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/8_test.sh b/tests/sys/geom/class/mirror/8_test.sh
--- a/tests/sys/geom/class/mirror/8_test.sh
+++ b/tests/sys/geom/class/mirror/8_test.sh
@@ -34,11 +34,11 @@
 exec 9>&-
 
 dd if=/dev/random of=$m1 bs=$ddbs count=1 conv=notrunc >/dev/null 2>&1
-us0=$(attach_md -t vnode -f $m1) || exit 1
+attach_md us0 -t vnode -f $m1 || exit 1
 devwait # This will take kern.geom.mirror.timeout seconds.
 
 # Re-attach the second mirror and wait for it to synchronize.
-us1=$(attach_md -t vnode -f $m2) || exit 1
+attach_md us1 -t vnode -f $m2 || exit 1
 syncwait
 
 # Verify the two mirrors are identical. Destroy the gmirror first so that
diff --git a/tests/sys/geom/class/mirror/9_test.sh b/tests/sys/geom/class/mirror/9_test.sh
--- a/tests/sys/geom/class/mirror/9_test.sh
+++ b/tests/sys/geom/class/mirror/9_test.sh
@@ -15,9 +15,9 @@
 dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
 dd if=/dev/zero of=$m3 bs=$ddbs count=1024 >/dev/null 2>&1
 
-us0=$(attach_md -t vnode -f $m1) || exit 1
-us1=$(attach_md -t vnode -f $m2) || exit 1
-us2=$(attach_md -t vnode -f $m3) || exit 1
+attach_md us0 -t vnode -f $m1 || exit 1
+attach_md us1 -t vnode -f $m2 || exit 1
+attach_md us2 -t vnode -f $m3 || exit 1
 
 gmirror label $name /dev/$us0 /dev/$us1 || exit 1
 devwait
diff --git a/tests/sys/geom/class/mirror/component_selection.sh b/tests/sys/geom/class/mirror/component_selection.sh
--- a/tests/sys/geom/class/mirror/component_selection.sh
+++ b/tests/sys/geom/class/mirror/component_selection.sh
@@ -29,9 +29,9 @@
 	dd if=/dev/urandom bs=512 count=1 of="$rnd1"
 	dd if=/dev/urandom bs=512 count=1 of="$rnd2"
 
-	md1=$(attach_md -t vnode -f ${f1})
-	md2=$(attach_md -t vnode -f ${f2})
-	md3=$(attach_md -t vnode -f ${f3})
+	attach_md md1 -t vnode -f ${f1}
+	attach_md md2 -t vnode -f ${f2}
+	attach_md md3 -t vnode -f ${f3}
 
 	# Use a gnop for md1 just for consistency; it's not used for anything.
 	atf_check gnop create $md1
diff --git a/tests/sys/geom/class/mirror/sync_error.sh b/tests/sys/geom/class/mirror/sync_error.sh
--- a/tests/sys/geom/class/mirror/sync_error.sh
+++ b/tests/sys/geom/class/mirror/sync_error.sh
@@ -21,8 +21,8 @@
 	atf_check dd if=/dev/zero bs=1M count=32 of=$f1 status=none
 	atf_check truncate -s 32M $f2 
 
-	md1=$(attach_md -t vnode -f ${f1})
-	md2=$(attach_md -t vnode -f ${f2})
+	attach_md md1 -t vnode -f ${f1}
+	attach_md md2 -t vnode -f ${f2}
 
 	atf_check gmirror label $name $md1
 	devwait
@@ -64,9 +64,9 @@
 	atf_check truncate -s 32M $f2
 	atf_check truncate -s 32M $f3
 
-	md1=$(attach_md -t vnode -f ${f1})
-	md2=$(attach_md -t vnode -f ${f2})
-	md3=$(attach_md -t vnode -f ${f3})
+	attach_md md1 -t vnode -f ${f1}
+	attach_md md2 -t vnode -f ${f2}
+	attach_md md3 -t vnode -f ${f3}
 
 	atf_check gmirror label $name $md1
 	devwait
diff --git a/tests/sys/geom/class/raid3/10_test.sh b/tests/sys/geom/class/raid3/10_test.sh
--- a/tests/sys/geom/class/raid3/10_test.sh
+++ b/tests/sys/geom/class/raid3/10_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/11_test.sh b/tests/sys/geom/class/raid3/11_test.sh
--- a/tests/sys/geom/class/raid3/11_test.sh
+++ b/tests/sys/geom/class/raid3/11_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/12_test.sh b/tests/sys/geom/class/raid3/12_test.sh
--- a/tests/sys/geom/class/raid3/12_test.sh
+++ b/tests/sys/geom/class/raid3/12_test.sh
@@ -8,9 +8,9 @@
 nblocks2=`expr $nblocks1 - 1`
 nblocks3=`expr $nblocks2 / 2`
 
-us0=$(attach_md -t malloc -s $nblocks1) || exit 1
-us1=$(attach_md -t malloc -s $nblocks1) || exit 1
-us2=$(attach_md -t malloc -s $nblocks1) || exit 1
+attach_md us0 -t malloc -s $nblocks1 || exit 1
+attach_md us1 -t malloc -s $nblocks1 || exit 1
+attach_md us2 -t malloc -s $nblocks1 || exit 1
 
 dd if=/dev/random of=/dev/${us0} count=$nblocks1 >/dev/null 2>&1
 dd if=/dev/random of=/dev/${us1} count=$nblocks1 >/dev/null 2>&1
diff --git a/tests/sys/geom/class/raid3/1_test.sh b/tests/sys/geom/class/raid3/1_test.sh
--- a/tests/sys/geom/class/raid3/1_test.sh
+++ b/tests/sys/geom/class/raid3/1_test.sh
@@ -4,9 +4,9 @@
 
 echo "1..2"
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 graid3 label $name /dev/${us0} /dev/${us1} /dev/${us2} 2>/dev/null || exit 1
 devwait
diff --git a/tests/sys/geom/class/raid3/2_test.sh b/tests/sys/geom/class/raid3/2_test.sh
--- a/tests/sys/geom/class/raid3/2_test.sh
+++ b/tests/sys/geom/class/raid3/2_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/3_test.sh b/tests/sys/geom/class/raid3/3_test.sh
--- a/tests/sys/geom/class/raid3/3_test.sh
+++ b/tests/sys/geom/class/raid3/3_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/4_test.sh b/tests/sys/geom/class/raid3/4_test.sh
--- a/tests/sys/geom/class/raid3/4_test.sh
+++ b/tests/sys/geom/class/raid3/4_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/5_test.sh b/tests/sys/geom/class/raid3/5_test.sh
--- a/tests/sys/geom/class/raid3/5_test.sh
+++ b/tests/sys/geom/class/raid3/5_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/6_test.sh b/tests/sys/geom/class/raid3/6_test.sh
--- a/tests/sys/geom/class/raid3/6_test.sh
+++ b/tests/sys/geom/class/raid3/6_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/7_test.sh b/tests/sys/geom/class/raid3/7_test.sh
--- a/tests/sys/geom/class/raid3/7_test.sh
+++ b/tests/sys/geom/class/raid3/7_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/8_test.sh b/tests/sys/geom/class/raid3/8_test.sh
--- a/tests/sys/geom/class/raid3/8_test.sh
+++ b/tests/sys/geom/class/raid3/8_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/raid3/9_test.sh b/tests/sys/geom/class/raid3/9_test.sh
--- a/tests/sys/geom/class/raid3/9_test.sh
+++ b/tests/sys/geom/class/raid3/9_test.sh
@@ -10,9 +10,9 @@
 src=`mktemp $base.XXXXXX` || exit 1
 dst=`mktemp $base.XXXXXX` || exit 1
 
-us0=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us1=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
-us2=$(attach_md -t malloc -s $(expr $nblocks1 + 1)) || exit 1
+attach_md us0 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us1 -t malloc -s $(expr $nblocks1 + 1) || exit 1
+attach_md us2 -t malloc -s $(expr $nblocks1 + 1) || exit 1
 
 dd if=/dev/random of=${src} bs=$ddbs count=$nblocks2 >/dev/null 2>&1
 
diff --git a/tests/sys/geom/class/shsec/1_test.sh b/tests/sys/geom/class/shsec/1_test.sh
--- a/tests/sys/geom/class/shsec/1_test.sh
+++ b/tests/sys/geom/class/shsec/1_test.sh
@@ -4,9 +4,9 @@
 
 echo "1..2"
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 gshsec label $name /dev/${us0} /dev/${us1} /dev/${us2} 2>/dev/null || exit 1
 devwait
diff --git a/tests/sys/geom/class/shsec/2_test.sh b/tests/sys/geom/class/shsec/2_test.sh
--- a/tests/sys/geom/class/shsec/2_test.sh
+++ b/tests/sys/geom/class/shsec/2_test.sh
@@ -11,9 +11,9 @@
 
 dd if=/dev/random of=${src} count=$nblocks1 >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s $nblocks2) || exit 1
-us1=$(attach_md -t malloc -s $nblocks2) || exit 1
-us2=$(attach_md -t malloc -s $nblocks2) || exit 1
+attach_md us0 -t malloc -s $nblocks2 || exit 1
+attach_md us1 -t malloc -s $nblocks2 || exit 1
+attach_md us2 -t malloc -s $nblocks2 || exit 1
 
 gshsec label $name /dev/$us0 /dev/$us1 /dev/$us2 || exit 1
 devwait
diff --git a/tests/sys/geom/class/stripe/1_test.sh b/tests/sys/geom/class/stripe/1_test.sh
--- a/tests/sys/geom/class/stripe/1_test.sh
+++ b/tests/sys/geom/class/stripe/1_test.sh
@@ -4,9 +4,9 @@
 
 echo "1..1"
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 gstripe create -s 16384 $name /dev/$us0 /dev/$us1 /dev/$us2 || exit 1
 devwait
diff --git a/tests/sys/geom/class/stripe/2_test.sh b/tests/sys/geom/class/stripe/2_test.sh
--- a/tests/sys/geom/class/stripe/2_test.sh
+++ b/tests/sys/geom/class/stripe/2_test.sh
@@ -10,9 +10,9 @@
 
 dd if=/dev/random of=${src} bs=1m count=$tsize >/dev/null 2>&1
 
-us0=$(attach_md -t malloc -s 1M) || exit 1
-us1=$(attach_md -t malloc -s 2M) || exit 1
-us2=$(attach_md -t malloc -s 3M) || exit 1
+attach_md us0 -t malloc -s 1M || exit 1
+attach_md us1 -t malloc -s 2M || exit 1
+attach_md us2 -t malloc -s 3M || exit 1
 
 gstripe create -s 8192 $name /dev/$us0 /dev/$us1 /dev/$us2 || exit 1
 devwait
diff --git a/tests/sys/geom/class/union/union_test.sh b/tests/sys/geom/class/union/union_test.sh
--- a/tests/sys/geom/class/union/union_test.sh
+++ b/tests/sys/geom/class/union/union_test.sh
@@ -39,8 +39,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     newfs -U "/dev/${lowerdev}"
 
     atf_check gunion create "$upperdev" "$lowerdev"
@@ -66,8 +66,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     newfs -U "/dev/${lowerdev}"
     mkdir lowermnt
     mkdir gunionmnt
@@ -109,8 +109,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     newfs -U "/dev/${lowerdev}"
     mkdir lowermnt
     mkdir gunionmnt
@@ -155,8 +155,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     gpart create -s GPT "/dev/${lowerdev}"
     gpart add -t freebsd-ufs "$lowerdev"
     newfs "/dev/${lowerdev}p1"
@@ -193,8 +193,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 2m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 2m
+    attach_md lowerdev -s 1m
     newfs -U "/dev/${lowerdev}"
 
     gunion create -s 2m "$upperdev" "$lowerdev"
@@ -219,8 +219,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     newfs -S 512 -U "/dev/${lowerdev}"
     lower_secsize="$(diskinfo "/dev/${lowerdev}" | awk '{print $2}')"
     atf_check_equal "512" "$lower_secsize"
@@ -247,8 +247,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     newfs -U "/dev/${lowerdev}"
 
     gunion create -Z gunion1 "$upperdev" "$lowerdev"
@@ -270,8 +270,8 @@
 {
     gunion_test_setup
 
-    upperdev="$(attach_md -s 1m)"
-    lowerdev="$(attach_md -s 1m)"
+    attach_md upperdev -s 1m
+    attach_md lowerdev -s 1m
     newfs -U "/dev/${lowerdev}"
     mkdir lowermnt
     mkdir gunionmnt
diff --git a/tests/sys/geom/class/uzip/1_test.sh b/tests/sys/geom/class/uzip/1_test.sh
--- a/tests/sys/geom/class/uzip/1_test.sh
+++ b/tests/sys/geom/class/uzip/1_test.sh
@@ -19,7 +19,7 @@
 echo "1..1"
 
 uudecode $UUE
-us0=$(attach_md -f $(basename $UUE .uue)) || exit 1
+attach_md us0 -f $(basename $UUE .uue) || exit 1
 sleep 1
 
 mount -o ro /dev/${us0}.uzip "${mntpoint}" || exit 1
diff --git a/tests/sys/kern/sendfile_test.sh b/tests/sys/kern/sendfile_test.sh
--- a/tests/sys/kern/sendfile_test.sh
+++ b/tests/sys/kern/sendfile_test.sh
@@ -54,7 +54,7 @@
 	    atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
 	fi
 
-	md=$(alloc_md)
+	alloc_md md
 	common_body_setup $md
 
 	atf_check $HELPER $FILE 0 0x10000 0x10000
@@ -77,7 +77,7 @@
 	    atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
 	fi
 
-	md=$(alloc_md)
+	alloc_md md
 	common_body_setup $md
 
 	atf_check gnop configure -r 100 -e 5 ${md}.nop
@@ -101,7 +101,7 @@
 	    atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
 	fi
 
-	md=$(alloc_md)
+	alloc_md md
 	common_body_setup $md
 
 	atf_check gnop configure -r 100 -e 5 ${md}.nop
@@ -122,12 +122,12 @@
 
 alloc_md()
 {
-	local md
+	local _md
 
 	[ -c /dev/mdctl ] || atf_skip "no /dev/mdctl to create md devices"
-	md=$(mdconfig -a -t swap -s 256M) || atf_fail "mdconfig -a failed"
-	echo ${md} >> $MD_DEVS
-	echo ${md}
+	_md=$(mdconfig -a -t swap -s 256M) || atf_fail "mdconfig -a failed"
+	echo ${_md} >> $MD_DEVS
+	eval "${1}='${_md}'"
 }
 
 common_body_setup()