for i in $(virsh list --all | awk '{print $2}'|grep -v Name);
do
virsh domblklist $i --details | awk '{print $4}'|grep -v Source;
done
I get
/sdc/kvm_strage/vm1.qcow2
/sdc/kvm_strage/vm1_1.qcow2
-
/sdc/kvm_strage/vm2.qcow2
-
/sdc/kvm_strage/vm3.qcow2
/sdc/kvm_strage/vm3_1.qcow2
-
But I want to get the path in a array and exclude the "-"
like
my_array=(/sdc/kvm_strage/vm1.qcow2 /sdc/kvm_strage/vm1_1.qcow2 /sdc/kvm_strage/vm2.qcow2 /sdc/kvm_strage/vm3.qcow2 /sdc/kvm_strage/vm3_1.qcow2)
How to do that?
Here is an alternative way:
declare -a my_array=($(for vm in $(virsh list --all --name); do
virsh domblklist $vm --details | awk '/disk/{print $4}'
done))
EDIT: I just noticed I missed a pair of parenthesis when setting the value of my_array
.