This would be traditional:
pvcreate /dev/md5 || die "pvcreate failed"
vgcreate vg0 /dev/md5 || die "vgcreate failed"
lvcreate -L 200MB vg0 -n test || die "lvcreate failed"
die is something you'll have to define, which prints an error message and then exits. A sample implementation might be
echo $@ 1>&2 # print arguments of 'die' to standard error
exit 1 # exit the script
When you do it like this, the script won't produce any output unless something fails, in which case it will not go any further. If you want it to keep going even if a command fails, remove the
exit line from the implementation of
If you want to get a message for each command that succeeds, as well, you could do this:
if pvcreate /dev/md5; then
echo "pvcreate succeeded"
echo "pvcreate failed"
and similarly for the other two commands.