[virt-tools-list] [PATCH 3/3] Be consistent with variable quoting and braces

Marc Fournier marc.fournier at camptocamp.com
Thu Apr 11 12:51:55 UTC 2013


---
 virt-what.in | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/virt-what.in b/virt-what.in
index c2dad16..1376ef4 100644
--- a/virt-what.in
+++ b/virt-what.in
@@ -60,7 +60,7 @@ while true; do
             root="$2"
             shift 2
             ;;
-	-v|--version) echo $VERSION; exit 0 ;;
+	-v|--version) echo "$VERSION"; exit 0 ;;
 	--) shift; break ;;
 	*) fail "internal error ($1)" ;;
     esac
@@ -71,7 +71,7 @@ done
 # Add /usr/libexec to the path so we can find the helper binary.
 prefix=@prefix@
 exec_prefix=@exec_prefix@
-PATH=$root at libexecdir@:$root/sbin:$root/usr/sbin:$PATH
+PATH="${root}@libexecdir@:${root}/sbin:${root}/usr/sbin:${PATH}"
 
 # Check we're running as root.
 
@@ -131,7 +131,7 @@ fi
 # container)
 # /proc/bc - exists on node, but not inside container.
 
-if [ -d $root/proc/vz -a ! -d $root/proc/bc ]; then
+if [ -d "${root}/proc/vz" -a ! -d "${root}/proc/bc" ]; then
     echo openvz
 fi
 
@@ -141,24 +141,24 @@ fi
 
 # LXC containers are based on cgroups. So first check if cgroups are present
 # in the running kernel.
-if [ -e $root/proc/self/cgroup ] &&
+if [ -e "${root}/proc/self/cgroup" ] &&
   # But if the last field of the cgroup colon-delimited file is "/", we are
   # outside of a container. So only proceed further if this field has more
   # characters.
-  grep -Eq '^[0-9]+:.+:/.+$' $root/proc/self/cgroup; then
+  grep -Eq '^[0-9]+:.+:/.+$' "${root}/proc/self/cgroup"; then
 
   # This is still not enough, as cgroups can be used for other things than LXC
   # containers. We base our final checks on the value/presence of various
   # environment variables passed to the "init" process.
-  for envvar in $(cat $root/proc/1/environ | tr '\000' '\n'); do
+  for envvar in $(cat "${root}/proc/1/environ" | tr '\000' '\n'); do
 
-    case $(echo $envvar | cut -f1 -d'=') in
+    case $(echo "$envvar" | cut -f1 -d'=') in
       # native lxc tools and virsh will set the "container" environment
       # variable to either "lxc", or "libvirt-lxc", or "libvirt", depending on
       # the version.
       container)
-        container_type=$(echo $envvar | while IFS='=' read k v; do echo $v; done)
-        if echo $container_type | grep -Eq '^(lxc|libvirt-lxc|libvirt)$'; then
+        container_type=$(echo "$envvar" | while IFS='=' read k v; do echo "$v"; done)
+        if echo "$container_type" | grep -Eq '^(lxc|libvirt-lxc|libvirt)$'; then
           echo lxc
           break
         fi
@@ -168,8 +168,8 @@ if [ -e $root/proc/self/cgroup ] &&
       # so the only way to detect them is via the "_" environment variable
       # (which is the command used to start the container).
       _)
-        external_command=$(echo $envvar | while IFS='=' read k v; do echo $v; done)
-        if echo $external_command | grep -iq 'lxc'; then
+        external_command=$(echo "$envvar" | while IFS='=' read k v; do echo "$v"; done)
+        if echo "$external_command" | grep -iq 'lxc'; then
           echo lxc
           break
         fi
@@ -188,18 +188,18 @@ if [ -e $root/proc/self/cgroup ] &&
 fi
 
 # Check for Linux-VServer
-if cat $root/proc/self/status | grep -q "VxID: [0-9]*"; then
+if cat "${root}/proc/self/status" | grep -q "VxID: [0-9]*"; then
     echo linux_vserver
 fi
 
 # Check for UML.
 # Added by Laurent Léonard.
-if grep -q 'UML' $root/proc/cpuinfo; then
+if grep -q 'UML' "${root}/proc/cpuinfo"; then
     echo uml
 fi
 
 # Check for IBM PowerVM Lx86 Linux/x86 emulator.
-if grep -q '^vendor_id.*PowerVM Lx86' $root/proc/cpuinfo; then
+if grep -q '^vendor_id.*PowerVM Lx86' "${root}/proc/cpuinfo"; then
     echo powervm_lx86
 fi
 
@@ -210,12 +210,12 @@ if echo "$dmi" | grep -q 'Manufacturer.*HITACHI' &&
 fi
 
 # Check for IBM SystemZ.
-if grep -q '^vendor_id.*IBM/S390' $root/proc/cpuinfo; then
+if grep -q '^vendor_id.*IBM/S390' "${root}/proc/cpuinfo"; then
     echo ibm_systemz
-    if [ -f $root/proc/sysinfo ]; then
-        if grep -q 'VM.*Control Program.*z/VM' $root/proc/sysinfo; then
+    if [ -f "${root}/proc/sysinfo" ]; then
+        if grep -q 'VM.*Control Program.*z/VM' "${root}/proc/sysinfo"; then
             echo ibm_systemz-zvm
-        elif grep -q '^LPAR' $root/proc/sysinfo; then
+        elif grep -q '^LPAR' "${root}/proc/sysinfo"; then
             echo ibm_systemz-lpar
         else
             # This is unlikely to be correct.
@@ -235,22 +235,22 @@ fi
 if [ "$cpuid" = "XenVMMXenVMM" ]; then
     echo xen; echo xen-hvm
     skip_qemu_kvm=true
-elif [ -f $root/proc/xen/capabilities ]; then
+elif [ -f "${root}/proc/xen/capabilities" ]; then
     echo xen
-    if grep -q "control_d" $root/proc/xen/capabilities; then
+    if grep -q "control_d" "${root}/proc/xen/capabilities"; then
         echo xen-dom0
     else
         echo xen-domU
     fi
     skip_qemu_kvm=true
-elif [ -f $root/sys/hypervisor/type ] &&
-    grep -q "xen" $root/sys/hypervisor/type; then
+elif [ -f "${root}/sys/hypervisor/type" ] &&
+    grep -q "xen" "${root}/sys/hypervisor/type"; then
     # Ordinary kernel with pv_ops.  There does not seem to be
     # enough information at present to tell whether this is dom0
     # or domU.  XXX
     echo xen
 elif [ "$arch" = "ia64" ]; then
-    if [ -d $root/sys/bus/xen -a ! -d $root/sys/bus/xen-backend ]; then
+    if [ -d "${root}/sys/bus/xen" -a ! -d "${root}/sys/bus/xen-backend" ]; then
         # PV-on-HVM drivers installed in a Xen guest.
         echo xen
         echo xen-hvm
@@ -273,7 +273,7 @@ fi
 # seen that it's Parallels.  Xen uses QEMU as the device model, so
 # skip this test if we know it is Xen.
 
-if ! $skip_qemu_kvm; then
+if ! "$skip_qemu_kvm"; then
     if [ "$cpuid" = "KVMKVMKVM" ]; then
 	echo kvm
     else
@@ -281,7 +281,7 @@ if ! $skip_qemu_kvm; then
         # option, since /proc/cpuinfo will not contain the QEMU
         # string.  The long term fix for this would be to export
         # another CPUID leaf for non-accelerated qemu.
-        if grep -q 'QEMU' $root/proc/cpuinfo; then
+        if grep -q 'QEMU' "${root}/proc/cpuinfo"; then
 	    echo qemu
 	fi
     fi
-- 
1.8.2.1




More information about the virt-tools-list mailing list