diff --git a/tools/hotplug/Linux/block b/tools/hotplug/Linux/block
index 2691b56951..bd41313bf8 100644
--- a/tools/hotplug/Linux/block
+++ b/tools/hotplug/Linux/block
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/block-common.sh"
 
 expand_dev() {
@@ -31,7 +31,7 @@
 # Not all distros have "losetup -f"
 find_free_loopback_dev() {
   local loopdev
-  loopdev=$(losetup -a | sed -e 's+^/dev/loop++' -e 's/:.*//' | find_free_loopback_helper)
+  loopdev=$(@losetup@  -a | @sed@ -e 's+^/dev/loop++' -e 's/:.*//' | find_free_loopback_helper)
   if [ -n "$loopdev" ] && [ -b "$loopdev" ]; then
     echo "$loopdev"
   fi
@@ -66,8 +66,8 @@
   then
     local inode="$4"
 
-    shared_list=$(losetup -a |
-          sed -n -e "s@^\([^:]\+\)\(:[[:blank:]]\[0*${dev}\]:${inode}[[:blank:]](.*)\)@\1@p" )
+    shared_list=$(@losetup@  -a |
+          @sed@ -n -e "s@^\([^:]\+\)\(:[[:blank:]]\[0*${dev}\]:${inode}[[:blank:]](.*)\)@\1@p" )
     for dev in $shared_list
     do
       if [ -n "$dev" ]
@@ -94,7 +94,7 @@
     toskip="^[^ ]* [^ ]* [^ ]* ro[, ]"
   fi
 
-  for file in $(cat /proc/mounts | grep -v "$toskip" | cut -f 1 -d ' ')
+  for file in $(@cat@ /proc/mounts | @grep@ -v "$toskip" | @cut@ -f 1 -d ' ')
   do
     if [ -e "$file" ]
     then
@@ -267,7 +267,7 @@
 
         if [ -L "$dev" ]
         then
-          dev=$(readlink -f "$dev") || fatal "$dev link does not exist."
+          dev=$(@readlink@ -f "$dev") || fatal "$dev link does not exist."
         fi
         test -e "$dev" || fatal "$dev does not exist."
         test -b "$dev" || fatal "$dev is not a block device."
@@ -282,7 +282,7 @@
       file)
         # Canonicalise the file, for sharing check comparison, and the mode
         # for ease of use here.
-        file=$(readlink -f "$p") || fatal "$p does not exist."
+        file=$(@readlink@ -f "$p") || fatal "$p does not exist."
         test -f "$file" || fatal "$file does not exist."
         mode=$(canonicalise_mode "$mode")
 
@@ -297,7 +297,7 @@
           fatal "Path closed or removed during hotplug add: $XENBUS_PATH state: $xenbus_state"
         fi
 
-        if [ "$mode" = 'w' ] && ! stat "$file" -c %A | grep -q w
+        if [ "$mode" = 'w' ] && ! @stat@ "$file" -c %A | @grep@ -q w
         then
           release_lock "block"
           ebusy \
@@ -307,8 +307,8 @@
 
         if [ "x$mode" != 'x!' ]
         then
-          inode=$(stat -c '%i' "$file")
-          dev=$(stat -c '%D' "$file")
+          inode=$(@stat@ -c '%i' "$file")
+          dev=$(@stat@ -c '%D' "$file")
           if [ -z "$inode" ] || [ -z "$dev" ]
           then
             fatal "Unable to lookup $file: dev: $dev inode: $inode"
@@ -317,20 +317,20 @@
           check_file_sharing "$file" "$dev" "$mode" "$inode"
         fi
 
-        loopdev=$(losetup -f 2>/dev/null || find_free_loopback_dev)
+        loopdev=$(@losetup@  -f 2>/dev/null || find_free_loopback_dev)
         if [ "$loopdev" = '' ]
         then
           release_lock "block"
           fatal 'Failed to find an unused loop device'
         fi
 
-        if LANG=C losetup -h 2>&1 | grep read-only >/dev/null
+        if LANG=C @losetup@  -h 2>&1 | @grep@ read-only >/dev/null
         then
           roflag="-$mode"; roflag="${roflag#-w}"; roflag="${roflag#-!}"
         else
           roflag=''
         fi
-        do_or_die losetup $roflag "$loopdev" "$file"
+        do_or_die @losetup@  $roflag "$loopdev" "$file"
         xenstore_write "$XENBUS_PATH/node" "$loopdev"
         write_dev "$loopdev"
         release_lock "block"
@@ -354,7 +354,7 @@
       file)
         claim_lock "block"
         node=$(xenstore_read "$XENBUS_PATH/node")
-	losetup -d "$node"
+	@losetup@  -d "$node"
         release_lock "block"
 	exit 0
 	;;
diff --git a/tools/hotplug/Linux/block-common.sh b/tools/hotplug/Linux/block-common.sh
index 5c80237d99..5e1c350555 100644
--- a/tools/hotplug/Linux/block-common.sh
+++ b/tools/hotplug/Linux/block-common.sh
@@ -15,7 +15,7 @@
 #
 
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/xen-hotplug-common.sh"
 
 findCommand "$@"
@@ -45,7 +45,7 @@
 # separated by a colon.
 device_major_minor()
 {
-  stat -L -c %t:%T "$1"
+  @stat@ -L -c %t:%T "$1"
 }
 
 
diff --git a/tools/hotplug/Linux/block-drbd-probe b/tools/hotplug/Linux/block-drbd-probe
index 7b2968b6d9..ba246cd132 100755
--- a/tools/hotplug/Linux/block-drbd-probe
+++ b/tools/hotplug/Linux/block-drbd-probe
@@ -31,8 +31,8 @@
 function get_res_name()
 {
     local drbd_dev=$1
-    local drbd_dev_list=($(drbdadm sh-dev all))
-    local drbd_res_list=($(drbdadm sh-resource all))
+    local drbd_dev_list=($(@drbdadm@ sh-dev all))
+    local drbd_res_list=($(@drbdadm@ sh-resource all))
     local temp_drbd_dev temp_drbd_res
     local found=0
 
@@ -48,7 +48,7 @@
     fi
 
     for temp_drbd_res in ${drbd_res_list[@]}; do
-        temp_drbd_dev=$(drbdadm sh-dev $temp_drbd_res)
+        temp_drbd_dev=$(@drbdadm@ sh-dev $temp_drbd_res)
         if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then
             drbd_res="$temp_drbd_res"
             return 0
@@ -66,19 +66,19 @@
 fi
 
 # check protocol
-drbdsetup $1 show | grep -q "protocol D;"
+@drbdsetup@ $1 show | @grep@ -q "protocol D;"
 if [[ $? -ne 0 ]]; then
     exit 3
 fi
 
 # check connect status
-state=$(drbdadm cstate "$drbd_res")
+state=$(@drbdadm@ cstate "$drbd_res")
 if [[ "$state" != "Connected" ]]; then
     exit 4
 fi
 
 # check role
-role=$(drbdadm role "$drbd_res")
+role=$(@drbdadm@ role "$drbd_res")
 if [[ "$role" != "Primary/Secondary" ]]; then
     exit 4
 fi
diff --git a/tools/hotplug/Linux/block-dummy b/tools/hotplug/Linux/block-dummy
index 57d40b5fce..50bbf09bb6 100644
--- a/tools/hotplug/Linux/block-dummy
+++ b/tools/hotplug/Linux/block-dummy
@@ -22,12 +22,12 @@
 #
 # script=block-dummy,vdev=xvda,target=dummy:<file>
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/block-common.sh"
 
 check_tools()
 {
-    if ! command -v losetup > /dev/null 2>&1; then
+    if ! command -v @losetup@  > /dev/null 2>&1; then
         fatal "Unable to find losetup"
     fi
 }
@@ -55,20 +55,20 @@
 {
     test -f "$file" || fatal "$file does not exist."
 
-    loopdev=$(losetup -f 2>/dev/null || find_free_loopback_dev)
+    loopdev=$(@losetup@  -f 2>/dev/null || find_free_loopback_dev)
     if [ "$loopdev" = '' ]
     then
         fatal 'Failed to find an unused loop device'
     fi
     
-    if LANG=C losetup -h 2>&1 | grep read-only >/dev/null
+    if LANG=C @losetup@  -h 2>&1 | @grep@ read-only >/dev/null
     then
         roflag="-$mode"; roflag="${roflag#-w}"; roflag="${roflag#-!}"
     else
         roflag=''
     fi
 
-    do_or_die losetup $roflag "$loopdev" "$file"
+    do_or_die @losetup@  $roflag "$loopdev" "$file"
     # FIXME Is this OK?
     xenstore_write "$XENBUS_PATH/node" "$loopdev"
     write_dev "$loopdev"
@@ -78,7 +78,7 @@
 remove()
 {
     node=$(xenstore_read "$XENBUS_PATH/node")
-    losetup -d "$node"
+    @losetup@  -d "$node"
 }
 
 command=$1
diff --git a/tools/hotplug/Linux/block-enbd b/tools/hotplug/Linux/block-enbd
index 67faa84268..77599ff6df 100644
--- a/tools/hotplug/Linux/block-enbd
+++ b/tools/hotplug/Linux/block-enbd
@@ -7,13 +7,13 @@
 #
 # This assumes you're running a correctly configured server at the other end!
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/block-common.sh"
 
 case "$command" in
   add)
     for dev in /dev/nd*; do
-      if nbd-client $2:$3 $dev; then
+      if @nbd-client@ $2:$3 $dev; then
         write_dev $dev
         exit 0
       fi
@@ -21,7 +21,7 @@
     exit 1
     ;;
   remove)
-    nbd-client -d $2
+    @nbd-client@ -d $2
     exit 0
     ;;
 esac
diff --git a/tools/hotplug/Linux/block-iscsi b/tools/hotplug/Linux/block-iscsi
index 3615905252..ad45a3685b 100644
--- a/tools/hotplug/Linux/block-iscsi
+++ b/tools/hotplug/Linux/block-iscsi
@@ -23,20 +23,20 @@
 # Portal address must be in IP format.
 #
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/block-common.sh"
 
 remove_label()
 {
-    echo $1 | sed "s/^\("$2"\)//"
+    echo $1 | @sed@ "s/^\("$2"\)//"
 }
 
 check_tools()
 {
-    if ! command -v iscsiadm > /dev/null 2>&1; then
+    if ! command -v @iscsiadm@ > /dev/null 2>&1; then
         fatal "Unable to find iscsiadm tool"
     fi
-    if [ "$multipath" = "y" ] && ! command -v multipath > /dev/null 2>&1; then
+    if [ "$multipath" = "y" ] && ! command -v @multipath@ > /dev/null 2>&1; then
         fatal "Unable to find multipath"
     fi
 }
@@ -74,19 +74,19 @@
 {
     count=0
     while [ ! -e /dev/disk/by-path/*"$iqn"-lun-0 ]; do
-        sleep 1
+        @sleep@ 1
         count=`expr $count + 1`
         if [ count = 100 ]; then
             # 10s timeout while waiting for iSCSI disk to settle
             fatal "timeout waiting for iSCSI disk to settle"
         fi
     done
-    sddev=$(readlink -f /dev/disk/by-path/*"$iqn"-lun-0 || true)
+    sddev=$(@readlink@ -f /dev/disk/by-path/*"$iqn"-lun-0 || true)
     if [ ! -b "$sddev" ]; then
         fatal "Unable to find attached device path"
     fi
     if [ "$multipath" = "y" ]; then
-        mdev=$(multipath -ll "$sddev" | head -1 | awk '{ print $1}')
+        mdev=$(@multipath@ -ll "$sddev" | @head@ -1 | @awk@ '{ print $1}')
         if [ ! -b /dev/mapper/"$mdev" ]; then
             fatal "Unable to find attached device multipath"
         fi
@@ -100,7 +100,7 @@
 # multipath device
 attach()
 {
-    do_or_die iscsiadm -m node --targetname "$iqn" -p "$portal" --login > /dev/null
+    do_or_die @iscsiadm@ -m node --targetname "$iqn" -p "$portal" --login > /dev/null
     find_device
 }
 
@@ -109,9 +109,9 @@
 prepare()
 {
     # Check if target is already opened
-    iscsiadm -m session 2>&1 | grep -q "$iqn" && fatal "Device already opened"
+    @iscsiadm@ -m session 2>&1 | @grep@ -q "$iqn" && fatal "Device already opened"
     # Discover portal targets
-    iscsiadm -m discovery -t st -p $portal 2>&1 | grep -q "$iqn" || \
+    @iscsiadm@ -m discovery -t st -p $portal 2>&1 | @grep@ -q "$iqn" || \
         fatal "No matching target iqn found"
 }
 
@@ -127,7 +127,7 @@
 remove()
 {
     find_device
-    do_or_die iscsiadm -m node --targetname "$iqn" -p "$portal" --logout > /dev/null
+    do_or_die @iscsiadm@ -m node --targetname "$iqn" -p "$portal" --logout > /dev/null
 }
 
 command=$1
diff --git a/tools/hotplug/Linux/block-nbd b/tools/hotplug/Linux/block-nbd
index b29b31564a..a98350b121 100644
--- a/tools/hotplug/Linux/block-nbd
+++ b/tools/hotplug/Linux/block-nbd
@@ -7,13 +7,13 @@
 #
 # This assumes you're running a correctly configured server at the other end!
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/block-common.sh"
 
 case "$command" in
   add)
     for dev in /dev/nbd*; do
-      if nbd-client $2 $3 $dev; then
+      if @nbd-client@ $2 $3 $dev; then
         write_dev $dev
         exit 0
       fi
@@ -21,7 +21,7 @@
     exit 1
     ;;
   remove)
-    nbd-client -d $2
+    @nbd-client@ -d $2
     exit 0
     ;;
 esac
diff --git a/tools/hotplug/Linux/block-tap b/tools/hotplug/Linux/block-tap
index 95970a61f6..a03a36f8b6 100755
--- a/tools/hotplug/Linux/block-tap
+++ b/tools/hotplug/Linux/block-tap
@@ -28,12 +28,12 @@
 #
 # format/<type> is either "aio" (for raw files), or "vhd"
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/block-common.sh"
 
 remove_label()
 {
-    echo $1 | sed "s/^\("$2"\)//"
+    echo $1 | @sed@ "s/^\("$2"\)//"
 }
 
 check_tools()
@@ -101,7 +101,7 @@
         for dev in $(xenstore-list "$base_path/$dom")
         do
             f=$(xenstore_read_default "$base_path/$dom/$dev/params" "")
-            f=$(echo "$f" | cut -d ":" -f 2)
+            f=$(echo "$f" | @cut@ -d ":" -f 2)
 
             if [ -n "$f" ] && [ "$file" = $f ] ; then
                 i=$(( i + 1 ))
@@ -130,7 +130,7 @@
     for dom in $(xenstore-list "$base_path") ; do
         for dev in $(xenstore-list "$base_path/$dom") ; do
             local f=$(xenstore_read_default "$base_path/$dom/$dev/params" "")
-            f=$(echo "$f" | cut -d ":" -f 2)
+            f=$(echo "$f" | @cut@ -d ":" -f 2)
 
             if [ -n "$f" ] && [ "$file" = "$f" ] ; then
                 if [ "$mode" = 'w' ] ; then
diff --git a/tools/hotplug/Linux/colo-proxy-setup b/tools/hotplug/Linux/colo-proxy-setup
index d709146c47..e0f44364cc 100755
--- a/tools/hotplug/Linux/colo-proxy-setup
+++ b/tools/hotplug/Linux/colo-proxy-setup
@@ -1,6 +1,6 @@
 #! /bin/bash
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/xen-hotplug-common.sh"
 . "$dir/hotplugpath.sh"
 
@@ -37,84 +37,84 @@
 
 function setup_primary()
 {
-    do_without_error tc qdisc add dev $vifname root handle 1: prio
-    do_without_error tc filter add dev $vifname parent 1: protocol ip prio 10 \
+    do_without_error @tc@ qdisc add dev $vifname root handle 1: prio
+    do_without_error @tc@ filter add dev $vifname parent 1: protocol ip prio 10 \
         u32 match u32 0 0 flowid 1:2 action mirred egress mirror dev $forwarddev
-    do_without_error tc filter add dev $vifname parent 1: protocol arp prio 11 \
+    do_without_error @tc@ filter add dev $vifname parent 1: protocol arp prio 11 \
         u32 match u32 0 0 flowid 1:2 action mirred egress mirror dev $forwarddev
-    do_without_error tc filter add dev $vifname parent 1: protocol ipv6 prio \
+    do_without_error @tc@ filter add dev $vifname parent 1: protocol ipv6 prio \
         12 u32 match u32 0 0 flowid 1:2 action mirred egress mirror \
         dev $forwarddev
 
-    do_without_error modprobe nf_conntrack_ipv4
-    do_without_error modprobe xt_PMYCOLO sec_dev=$forwarddev
+    do_without_error @modprobe@ nf_conntrack_ipv4
+    do_without_error @modprobe@ xt_PMYCOLO sec_dev=$forwarddev
 
-    iptables -t mangle -I PREROUTING -m physdev --physdev-in \
+    @iptables@ -t mangle -I PREROUTING -m physdev --physdev-in \
         $vifname -j PMYCOLO --index $index
-    ip6tables -t mangle -I PREROUTING -m physdev --physdev-in \
+    @ip6tables@ -t mangle -I PREROUTING -m physdev --physdev-in \
         $vifname -j PMYCOLO --index $index
-    do_without_error arptables -I INPUT -i $forwarddev -j MARK --set-mark $index
+    do_without_error @arptables@ -I INPUT -i $forwarddev -j MARK --set-mark $index
 }
 
 function teardown_primary()
 {
-    do_without_error tc filter del dev $vifname parent 1: protocol ip prio 10 u32 match u32 \
+    do_without_error @tc@ filter del dev $vifname parent 1: protocol ip prio 10 u32 match u32 \
         0 0 flowid 1:2 action mirred egress mirror dev $forwarddev
-    do_without_error tc filter del dev $vifname parent 1: protocol arp prio 11 u32 match u32 \
+    do_without_error @tc@ filter del dev $vifname parent 1: protocol arp prio 11 u32 match u32 \
         0 0 flowid 1:2 action mirred egress mirror dev $forwarddev
-    do_without_error tc filter del dev $vifname parent 1: protocol ipv6 prio 12 u32 match u32 \
+    do_without_error @tc@ filter del dev $vifname parent 1: protocol ipv6 prio 12 u32 match u32 \
         0 0 flowid 1:2 action mirred egress mirror dev $forwarddev
-    do_without_error tc qdisc del dev $vifname root handle 1: prio
+    do_without_error @tc@ qdisc del dev $vifname root handle 1: prio
 
-    do_without_error iptables -t mangle -D PREROUTING -m physdev --physdev-in \
+    do_without_error @iptables@ -t mangle -D PREROUTING -m physdev --physdev-in \
         $vifname -j PMYCOLO --index $index
-    do_without_error ip6tables -t mangle -D PREROUTING -m physdev --physdev-in \
+    do_without_error @ip6tables@ -t mangle -D PREROUTING -m physdev --physdev-in \
         $vifname -j PMYCOLO --index $index
-    do_without_error arptables -F
-    do_without_error rmmod xt_PMYCOLO
+    do_without_error @arptables@ -F
+    do_without_error @rmmod@ xt_PMYCOLO
 }
 
 function setup_secondary()
 {
-    if which brctl >&/dev/null; then
-        do_without_error brctl delif $bridge $vifname
-        do_without_error brctl addbr $forwardbr
-        do_without_error brctl addif $forwardbr $vifname
-        do_without_error brctl addif $forwardbr $forwarddev
+    if @which@ @brctl@ >&/dev/null; then
+        do_without_error @brctl@ delif $bridge $vifname
+        do_without_error @brctl@ addbr $forwardbr
+        do_without_error @brctl@ addif $forwardbr $vifname
+        do_without_error @brctl@ addif $forwardbr $forwarddev
     else
-        do_without_error ip link set $vifname nomaster
-        do_without_error ip link add name $forwardbr type bridge
-        do_without_error ip link set $vifname master $forwardbr
-        do_without_error ip link set $forwarddev master $forwardbr
+        do_without_error @ip@ link set $vifname nomaster
+        do_without_error @ip@ link add name $forwardbr type bridge
+        do_without_error @ip@ link set $vifname master $forwardbr
+        do_without_error @ip@ link set $forwarddev master $forwardbr
     fi
-    do_without_error ip link set dev $forwardbr up
-    do_without_error modprobe xt_SECCOLO
+    do_without_error @ip@ link set dev $forwardbr up
+    do_without_error @modprobe@ xt_SECCOLO
 
-    iptables -t mangle -I PREROUTING -m physdev --physdev-in \
+    @iptables@ -t mangle -I PREROUTING -m physdev --physdev-in \
         $vifname -j SECCOLO --index $index
-    ip6tables -t mangle -I PREROUTING -m physdev --physdev-in \
+    @ip6tables@ -t mangle -I PREROUTING -m physdev --physdev-in \
         $vifname -j SECCOLO --index $index
 }
 
 function teardown_secondary()
 {
-    if which brctl >&/dev/null; then
-        do_without_error brctl delif $forwardbr $forwarddev
-        do_without_error brctl delif $forwardbr $vifname
-        do_without_error brctl delbr $forwardbr
-        do_without_error brctl addif $bridge $vifname
+    if @which@ @brctl@ >&/dev/null; then
+        do_without_error @brctl@ delif $forwardbr $forwarddev
+        do_without_error @brctl@ delif $forwardbr $vifname
+        do_without_error @brctl@ delbr $forwardbr
+        do_without_error @brctl@ addif $bridge $vifname
     else
-        do_without_error ip link set $forwarddev nomaster
-        do_without_error ip link set $vifname nomaster
-        do_without_error ip link delete $forwardbr type bridge
-        do_without_error ip link set $vifname master $bridge
+        do_without_error @ip@ link set $forwarddev nomaster
+        do_without_error @ip@ link set $vifname nomaster
+        do_without_error @ip@ link delete $forwardbr type bridge
+        do_without_error @ip@ link set $vifname master $bridge
     fi
 
-    do_without_error iptables -t mangle -D PREROUTING -m physdev --physdev-in \
+    do_without_error @iptables@ -t mangle -D PREROUTING -m physdev --physdev-in \
         $vifname -j SECCOLO --index $index
-    do_without_error ip6tables -t mangle -D PREROUTING -m physdev --physdev-in \
+    do_without_error @ip6tables@ -t mangle -D PREROUTING -m physdev --physdev-in \
         $vifname -j SECCOLO --index $index
-    do_without_error rmmod xt_SECCOLO
+    do_without_error @rmmod@ xt_SECCOLO
 }
 
 case "$command" in
diff --git a/tools/hotplug/Linux/external-device-migrate b/tools/hotplug/Linux/external-device-migrate
index f5942a6a95..228917b784 100644
--- a/tools/hotplug/Linux/external-device-migrate
+++ b/tools/hotplug/Linux/external-device-migrate
@@ -23,12 +23,12 @@
 # It handles the low-level command line parsing and some of the
 # synchronization
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/logging.sh"
 
 
 function ext_dev_migrate_usage() {
-cat <<EOF
+@cat@ <<EOF
 Pass the following command line parameters to the script:
 
 -step <n>              : n-th migration step
diff --git a/tools/hotplug/Linux/init.d/xencommons.in b/tools/hotplug/Linux/init.d/xencommons.in
index 7fd6903b98..dcc8de631b 100644
--- a/tools/hotplug/Linux/init.d/xencommons.in
+++ b/tools/hotplug/Linux/init.d/xencommons.in
@@ -38,7 +38,7 @@
 # mount xenfs in dom0 or domU with a pv_ops kernel
 if test "x$1" = xstart && \
    ! test -f /proc/xen/capabilities && \
-   ! grep '^xenfs ' /proc/mounts >/dev/null;
+   ! @grep@ '^xenfs ' /proc/mounts >/dev/null;
 then
 	mount -t xenfs xenfs /proc/xen
 fi
@@ -47,18 +47,18 @@
 # no capabilities file in xenlinux domU kernel
 # empty capabilities file in pv_ops domU kernel
 if test -f /proc/xen/capabilities && \
-   ! grep -q "control_d" /proc/xen/capabilities ; then
+   ! @grep@ -q "control_d" /proc/xen/capabilities ; then
 	exit 0
 fi
 
 do_start () {
 	local mod
 
-	for mod in $BACKEND_MODULES ; do modprobe "$mod" &>/dev/null ; done
+	for mod in $BACKEND_MODULES ; do @modprobe@ "$mod" &>/dev/null ; done
 
-	mkdir -m700 -p ${XEN_RUN_DIR}
-	mkdir -m700 -p ${XEN_LOCK_DIR}
-	mkdir -p ${XEN_LOG_DIR}
+	@mkdir@ -m700 -p ${XEN_RUN_DIR}
+	@mkdir@ -m700 -p ${XEN_LOCK_DIR}
+	@mkdir@ -p ${XEN_LOG_DIR}
 
 	@XEN_SCRIPT_DIR@/launch-xenstore || exit 1
 
@@ -78,15 +78,15 @@
         echo Stopping xenconsoled
 	if read 2>/dev/null <$XENCONSOLED_PIDFILE pid; then
 		kill $pid
-		while kill -9 $pid >/dev/null 2>&1; do sleep 1; done
-		rm -f $XENCONSOLED_PIDFILE
+		while kill -9 $pid >/dev/null 2>&1; do @sleep@ 1; done
+		@rm@ -f $XENCONSOLED_PIDFILE
 	fi
 
 	echo Stopping QEMU
 	if read 2>/dev/null <$QEMU_PIDFILE pid; then
 		kill $pid
-		while kill -9 $pid >/dev/null 2>&1; do sleep 1; done
-		rm -f $QEMU_PIDFILE
+		while kill -9 $pid >/dev/null 2>&1; do @sleep@ 1; done
+		@rm@ -f $QEMU_PIDFILE
 	fi
 
 	echo WARNING: Not stopping xenstored, as it cannot be restarted.
diff --git a/tools/hotplug/Linux/init.d/xendriverdomain.in b/tools/hotplug/Linux/init.d/xendriverdomain.in
index 17b381c3dc..064906f027 100644
--- a/tools/hotplug/Linux/init.d/xendriverdomain.in
+++ b/tools/hotplug/Linux/init.d/xendriverdomain.in
@@ -34,7 +34,7 @@
 # mount xenfs in dom0 or domU with a pv_ops kernel
 if test "x$1" = xstart && \
    ! test -f /proc/xen/capabilities && \
-   ! grep '^xenfs ' /proc/mounts >/dev/null;
+   ! @grep@ '^xenfs ' /proc/mounts >/dev/null;
 then
 	mount -t xenfs xenfs /proc/xen
 fi
@@ -43,21 +43,21 @@
 # no capabilities file in xenlinux domU kernel
 # empty capabilities file in pv_ops domU kernel
 if ! test -f /proc/xen/capabilities || \
-   grep -q "control_d" /proc/xen/capabilities ; then
+   @grep@ -q "control_d" /proc/xen/capabilities ; then
 	exit 0
 fi
 
 do_start () {
 	echo Starting xl devd...
-	mkdir -p "${XEN_RUN_DIR}"
+	@mkdir@ -p "${XEN_RUN_DIR}"
 	${sbindir}/xl devd --pidfile=$XLDEVD_PIDFILE $XLDEVD_ARGS
 }
 do_stop () {
         echo Stopping xl devd...
 	if read 2>/dev/null <$XLDEVD_PIDFILE pid; then
 		kill $pid
-		while kill -9 $pid >/dev/null 2>&1; do sleep 1; done
-		rm -f $XLDEVD_PIDFILE
+		while kill -9 $pid >/dev/null 2>&1; do @sleep@ 1; done
+		@rm@ -f $XLDEVD_PIDFILE
 	fi
 }
 
diff --git a/tools/hotplug/Linux/init.d/xen-watchdog.in b/tools/hotplug/Linux/init.d/xen-watchdog.in
index a0bde199c4..cefa3b81f8 100644
--- a/tools/hotplug/Linux/init.d/xen-watchdog.in
+++ b/tools/hotplug/Linux/init.d/xen-watchdog.in
@@ -25,7 +25,7 @@
 
 test -n "$XENWATCHDOGD_ARGS" || XENWATCHDOGD_ARGS='30 15'
 DAEMON=${sbindir}/xenwatchdogd
-base=$(basename $DAEMON)
+base=$(@basename@ $DAEMON)
 
 # Source function library.
 if [ -e  /etc/init.d/functions ] ; then
@@ -63,7 +63,7 @@
 	local r
 	echo -n $"Stopping domain watchdog daemon: "
 
-	killall -USR1 $base 2>/dev/null
+	@killall@ -USR1 $base 2>/dev/null
 	r=$?
 	[ "$r" -eq 0 ] && success $"$base stop" || failure $"$base stop"
 	echo
diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/launch-xenstore.in
index da4eeca7c5..059036d899 100644
--- a/tools/hotplug/Linux/launch-xenstore.in
+++ b/tools/hotplug/Linux/launch-xenstore.in
@@ -31,7 +31,7 @@
 	while [ $time -lt $timeout ] && ! test_xenstore ; do
 		echo -n .
 		time=$(($time+1))
-		sleep 1
+		@sleep@ 1
 	done
 	echo
  
@@ -50,7 +50,7 @@
 
 [ "$XENSTORETYPE" = "" ] && XENSTORETYPE=daemon
 
-/bin/mkdir -p @XEN_RUN_DIR@
+@mkdir@ -p @XEN_RUN_DIR@
 
 [ "$XENSTORETYPE" = "daemon" ] && {
 	[ -z "$XENSTORED_TRACE" ] || XENSTORED_ARGS="$XENSTORED_ARGS -T @XEN_LOG_DIR@/xenstored-trace.log"
@@ -71,7 +71,7 @@
 		}
 	}
 	[ -r /proc/sys/fs/nr_open ] && {
-		MAX_FDS=`cat /proc/sys/fs/nr_open`
+		MAX_FDS=`@cat@ /proc/sys/fs/nr_open`
 		[ "$XENSTORED_MAX_OPEN_FDS" = "unlimited" ] && XENSTORED_MAX_OPEN_FDS=$MAX_FDS
 		[ $XENSTORED_MAX_OPEN_FDS -gt $MAX_FDS ] && {
 			echo "XENSTORED_MAX_OPEN_FDS exceeds system limit."
@@ -80,13 +80,13 @@
 		}
 	}
 
-	rm -f @XEN_RUN_DIR@/xenstored.pid
+	@rm@ -f @XEN_RUN_DIR@/xenstored.pid
 
 	echo -n Starting $XENSTORED...
-	prlimit --nofile=$XENSTORED_MAX_OPEN_FDS $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS
+	@prlimit@ --nofile=$XENSTORED_MAX_OPEN_FDS $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS
 
-	systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exit 1
-	XS_PID=`cat @XEN_RUN_DIR@/xenstored.pid`
+	@systemd-notify@ --booted 2>/dev/null || timeout_xenstore $XENSTORED || exit 1
+	XS_PID=`@cat@ @XEN_RUN_DIR@/xenstored.pid`
 	echo $XS_OOM_SCORE >/proc/$XS_PID/oom_score_adj
 
 	exit 0
@@ -102,7 +102,7 @@
 
 	echo -n Starting $XENSTORE_DOMAIN_KERNEL...
 	${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS || exit 1
-	systemd-notify --ready 2>/dev/null
+	@systemd-notify@ --ready 2>/dev/null
 
 	exit 0
 }
diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh
index 2e6fb35f02..5860157657 100644
--- a/tools/hotplug/Linux/locking.sh
+++ b/tools/hotplug/Linux/locking.sh
@@ -35,7 +35,7 @@
 
 claim_lock()
 {
-    mkdir -p "$LOCK_BASEDIR"
+    @mkdir@ -p "$LOCK_BASEDIR"
     _setlockfd $1
     # The locking strategy is identical to that from with-lock-ex(1)
     # from chiark-utils, except using flock.  It has the benefit of
@@ -44,7 +44,7 @@
     local stat
     while true; do
         eval "exec $_lockfd<>$_lockfile"
-        flock -x $_lockfd || return $?
+        @flock@ -x $_lockfd || return $?
         # Although /dev/stdin (i.e. /proc/self/fd/0) looks like a symlink,
         # stat(2) bypasses the synthetic symlink and directly accesses the
         # underlying open-file.  So this works correctly even if the file
@@ -52,7 +52,7 @@
         # WW.XXX
         # YY.ZZZ
         # which need to be separated and compared.
-        if stat=$( stat -L -c '%D.%i' /dev/stdin $_lockfile 0<&$_lockfd 2>/dev/null )
+        if stat=$( @stat@ -L -c '%D.%i' /dev/stdin $_lockfile 0<&$_lockfd 2>/dev/null )
         then
             local file_stat
             local fd_stat
@@ -74,7 +74,7 @@
 release_lock()
 {
     _setlockfd $1
-    rm "$_lockfile"
+    @rm@ "$_lockfile"
 }
 
 # Protocol and correctness proof:
diff --git a/tools/hotplug/Linux/logging.sh b/tools/hotplug/Linux/logging.sh
index 3e94df1a9e..fa99d8c4c7 100644
--- a/tools/hotplug/Linux/logging.sh
+++ b/tools/hotplug/Linux/logging.sh
@@ -17,5 +17,5 @@
 log() {
   local level="$1"
   shift
-  logger -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2
+  @logger@ -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2
 }
diff --git a/tools/hotplug/Linux/remus-netbuf-setup b/tools/hotplug/Linux/remus-netbuf-setup
index 87dfa69778..fe4f7b6e36 100644
--- a/tools/hotplug/Linux/remus-netbuf-setup
+++ b/tools/hotplug/Linux/remus-netbuf-setup
@@ -74,7 +74,7 @@
 
 # Unlike other vif scripts, vif-common is not needed here as it executes vif
 #specific setup code such as renaming.
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/xen-hotplug-common.sh"
 
 findCommand "$@"
@@ -92,13 +92,13 @@
 : ${XENBUS_PATH:?}
 
 check_libnl_tools() {
-    if ! command -v nl-qdisc-list > /dev/null 2>&1; then
+    if ! command -v @nl-qdisc-list@ > /dev/null 2>&1; then
         fatal "Unable to find nl-qdisc-list tool"
     fi
-    if ! command -v nl-qdisc-add > /dev/null 2>&1; then
+    if ! command -v @nl-qdisc-add@ > /dev/null 2>&1; then
         fatal "Unable to find nl-qdisc-add tool"
     fi
-    if ! command -v nl-qdisc-delete > /dev/null 2>&1; then
+    if ! command -v @nl-qdisc-delete@ > /dev/null 2>&1; then
         fatal "Unable to find nl-qdisc-delete tool"
     fi
 }
@@ -110,7 +110,7 @@
 check_modules() {
     for m in ifb sch_plug sch_ingress act_mirred cls_u32
     do
-        if ! modinfo $m > /dev/null 2>&1; then
+        if ! @modinfo@ $m > /dev/null 2>&1; then
             fatal "Unable to find $m kernel module"
         fi
     done
@@ -118,7 +118,7 @@
 
 #return 0 if the ifb is free
 check_ifb() {
-    local installed=`nl-qdisc-list -d $1`
+    local installed=`@nl-qdisc-list@ -d $1`
     [ -n "$installed" ] && return 1
 
     for domid in `xenstore-list "/local/domain" 2>/dev/null || true`
@@ -139,7 +139,7 @@
 
 setup_ifb() {
 
-    for ifb in `ifconfig -a -s|egrep ^ifb|cut -d ' ' -f1`
+    for ifb in `@ifconfig@ -a -s|@egrep@ ^ifb|@cut@ -d ' ' -f1`
     do
         check_ifb "$ifb" || continue
         REMUS_IFB="$ifb"
@@ -154,21 +154,21 @@
     #not using xenstore_write that automatically exits on error
     #because we need to cleanup
     xenstore_write "$XENBUS_PATH/ifb" "$REMUS_IFB"
-    do_or_die ip link set dev "$REMUS_IFB" up
+    do_or_die @ip@ link set dev "$REMUS_IFB" up
 }
 
 redirect_vif_traffic() {
     local vif=$1
     local ifb=$2
 
-    do_or_die tc qdisc add dev "$vif" ingress
+    do_or_die @tc@ qdisc add dev "$vif" ingress
 
-    tc filter add dev "$vif" parent ffff: proto ip prio 10 \
+    @tc@ filter add dev "$vif" parent ffff: proto ip prio 10 \
         u32 match u32 0 0 action mirred egress redirect dev "$ifb" >/dev/null 2>&1
 
     if [ $? -ne 0 ]
     then
-        do_without_error tc qdisc del dev "$vif" ingress
+        do_without_error @tc@ qdisc del dev "$vif" ingress
         fatal "Failed to redirect traffic from $vif to $ifb"
     fi
 }
@@ -177,15 +177,15 @@
     local vif=$1
     local ifb=$2
 
-    nl-qdisc-add --dev="$ifb" --parent root plug >/dev/null 2>&1
+    @nl-qdisc-add@ --dev="$ifb" --parent root plug >/dev/null 2>&1
     if [ $? -ne 0 ]
     then
-        do_without_error tc qdisc del dev "$vif" ingress
+        do_without_error @tc@ qdisc del dev "$vif" ingress
         fatal "Failed to add plug qdisc to $ifb"
     fi
 
     #set ifb buffering limit in bytes. Its okay if this command fails
-    nl-qdisc-add --dev="$ifb" --parent root \
+    @nl-qdisc-add@ --dev="$ifb" --parent root \
         --update plug --limit=10000000 >/dev/null 2>&1 || true
 }
 
@@ -200,11 +200,11 @@
         local ifb2=`xenstore-read "$XENBUS_PATH/ifb" 2>/dev/null || true`
 
     if [[ "$ifb2" && "$ifb2" == "$ifb" ]]; then
-        do_without_error ip link set dev "$ifb" down
-        do_without_error nl-qdisc-delete --dev="$ifb" --parent root plug >/dev/null 2>&1
+        do_without_error @ip@ link set dev "$ifb" down
+        do_without_error @nl-qdisc-delete@ --dev="$ifb" --parent root plug >/dev/null 2>&1
         xenstore-rm -t "$XENBUS_PATH/ifb" 2>/dev/null || true
     fi
-    do_without_error tc qdisc del dev "$vif" ingress
+    do_without_error @tc@ qdisc del dev "$vif" ingress
     xenstore-rm -t "$XENBUS_PATH/hotplug-status" 2>/dev/null || true
     xenstore-rm -t "$XENBUS_PATH/hotplug-error" 2>/dev/null || true
 }
diff --git a/tools/hotplug/Linux/systemd/xenconsoled.service.in b/tools/hotplug/Linux/systemd/xenconsoled.service.in
index d84c09aa9c..68317246ae 100644
--- a/tools/hotplug/Linux/systemd/xenconsoled.service.in
+++ b/tools/hotplug/Linux/systemd/xenconsoled.service.in
@@ -10,8 +10,8 @@
 Environment=XENCONSOLED_TRACE=none
 Environment=XENCONSOLED_LOG_DIR=@XEN_LOG_DIR@/console
 EnvironmentFile=-@CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons
-ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
-ExecStartPre=/bin/mkdir -p ${XENCONSOLED_LOG_DIR} @XEN_RUN_DIR@
+ExecStartPre=@grep@ -q control_d /proc/xen/capabilities
+ExecStartPre=@mkdir@ -p ${XENCONSOLED_LOG_DIR} @XEN_RUN_DIR@
 ExecStart=@sbindir@/xenconsoled -i --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS
 
 [Install]
diff --git a/tools/hotplug/Linux/systemd/xendomains.service.in b/tools/hotplug/Linux/systemd/xendomains.service.in
index c7bfb61eb4..314ed9e91a 100644
--- a/tools/hotplug/Linux/systemd/xendomains.service.in
+++ b/tools/hotplug/Linux/systemd/xendomains.service.in
@@ -10,7 +10,7 @@
 [Service]
 Type=oneshot
 RemainAfterExit=true
-ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStartPre=@grep@ -q control_d /proc/xen/capabilities
 ExecStart=-@LIBEXEC_BIN@/xendomains start
 ExecStop=@LIBEXEC_BIN@/xendomains stop
 ExecReload=@LIBEXEC_BIN@/xendomains restart
diff --git a/tools/hotplug/Linux/systemd/xen-init-dom0.service.in b/tools/hotplug/Linux/systemd/xen-init-dom0.service.in
index 98779b8507..cc75339377 100644
--- a/tools/hotplug/Linux/systemd/xen-init-dom0.service.in
+++ b/tools/hotplug/Linux/systemd/xen-init-dom0.service.in
@@ -8,7 +8,7 @@
 Type=oneshot
 RemainAfterExit=true
 EnvironmentFile=-@CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons
-ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStartPre=@grep@ -q control_d /proc/xen/capabilities
 ExecStart=@LIBEXEC_BIN@/xen-init-dom0 $XEN_DOM0_UUID
 
 [Install]
diff --git a/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in b/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
index f56775bc87..a9091047da 100644
--- a/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
+++ b/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
@@ -9,8 +9,8 @@
 [Service]
 Type=simple
 PIDFile=@XEN_RUN_DIR@/qemu-dom0.pid
-ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
-ExecStartPre=/bin/mkdir -p @XEN_RUN_DIR@
+ExecStartPre=@grep@ -q control_d /proc/xen/capabilities
+ExecStartPre=@mkdir@ -p @XEN_RUN_DIR@
 ExecStart=@qemu_xen_systemd@ -xen-domid 0 \
 	-xen-attach -name dom0 -nographic -M xenpv -daemonize \
 	-monitor /dev/null -serial /dev/null -parallel /dev/null \
diff --git a/tools/hotplug/Linux/systemd/xenstored.service.in b/tools/hotplug/Linux/systemd/xenstored.service.in
index 261077dc92..7daf7369b8 100644
--- a/tools/hotplug/Linux/systemd/xenstored.service.in
+++ b/tools/hotplug/Linux/systemd/xenstored.service.in
@@ -10,7 +10,7 @@
 Type=notify
 NotifyAccess=all
 RemainAfterExit=true
-ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStartPre=@grep@ -q control_d /proc/xen/capabilities
 ExecStart=@XEN_SCRIPT_DIR@/launch-xenstore
 
 [Install]
diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge
index 6164c7a52f..e219ae1b47 100644
--- a/tools/hotplug/Linux/vif-bridge
+++ b/tools/hotplug/Linux/vif-bridge
@@ -25,17 +25,17 @@
 # rules for its ip addresses (if any).
 #============================================================================
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/vif-common.sh"
 
 bridge=${bridge:-}
 bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
 
 if [ -z "$bridge" ]; then
-    if which brctl >&/dev/null; then
-        bridge=$(brctl show | awk 'NR==2{print$1}')
+    if @which@ @brctl@ >&/dev/null; then
+        bridge=$(@brctl@ show | @awk@ 'NR==2{print$1}')
     else
-        bridge=$(bridge link | cut -d" " -f7)
+        bridge=$(@bridge@ link | @cut@ -d" " -f7)
     fi
   if [ -z "$bridge" ]
   then
@@ -70,7 +70,7 @@
 fi
 
 RET=0
-ip link show dev "$bridge" 1>/dev/null 2>&1 || RET=1
+@ip@ link show dev "$bridge" 1>/dev/null 2>&1 || RET=1
 if [ "$RET" -eq 1 ]
 then
     fatal "Could not find bridge device $bridge"
diff --git a/tools/hotplug/Linux/vif-common.sh b/tools/hotplug/Linux/vif-common.sh
index a8e65178f9..28eb851f94 100644
--- a/tools/hotplug/Linux/vif-common.sh
+++ b/tools/hotplug/Linux/vif-common.sh
@@ -15,7 +15,7 @@
 #
 
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/xen-hotplug-common.sh"
 . "$dir/xen-network-common.sh"
 
@@ -72,11 +72,11 @@
     # already exists, then stop, before messing up whatever is using
     # that interface (e.g. another running domU) because it's likely a
     # configuration error
-    if ip link show "$vifname" >&/dev/null
+    if @ip@ link show "$vifname" >&/dev/null
     then
         fatal "Cannot rename interface $dev. An interface with name $vifname already exists."
     fi
-    do_or_die ip link set "$dev" name "$vifname"
+    do_or_die @ip@ link set "$dev" name "$vifname"
 }
 
 if [ "$type_if" = vif ]; then
@@ -134,12 +134,12 @@
 iptables_w()
 {
     if ! $IPTABLES_WAIT_RUNE_CHECKED ; then
-	iptables $IPTABLES_WAIT_RUNE -L -n >& /dev/null
+	@iptables@ $IPTABLES_WAIT_RUNE -L -n >& /dev/null
 	if [[ $? == 0 ]] ; then
 	    # If we succeed, then -w is supported; don't check again
 	    IPTABLES_WAIT_RUNE_CHECKED=true
 	elif [[ $? == 2 ]] ; then
-	    iptables -L -n >& /dev/null
+	    @iptables@ -L -n >& /dev/null
 	    if [[ $? != 2 ]] ; then
 		# If we fail with PARAMETER_PROBLEM (2) with -w and
 		# don't fail with PARAMETER_PROBLEM without it, then
@@ -149,7 +149,7 @@
 	    fi
 	fi
     fi
-    iptables $IPTABLES_WAIT_RUNE "$@"
+    @iptables@ $IPTABLES_WAIT_RUNE "$@"
 }
 
 frob_iptable()
@@ -220,7 +220,7 @@
 #
 ip_of()
 {
-  ip -4 -o addr show primary dev "$1" | awk '$3 == "inet" {split($4,i,"/"); print i[1]; exit}'
+  @ip@ -4 -o addr show primary dev "$1" | @awk@ '$3 == "inet" {split($4,i,"/"); print i[1]; exit}'
 }
 
 
diff --git a/tools/hotplug/Linux/vif-nat b/tools/hotplug/Linux/vif-nat
index fd34afbb96..8921de58f3 100644
--- a/tools/hotplug/Linux/vif-nat
+++ b/tools/hotplug/Linux/vif-nat
@@ -21,7 +21,7 @@
 #============================================================================
 
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/vif-common.sh"
 
 # turn on dhcp feature by default if dhcpd is installed
@@ -61,7 +61,7 @@
 
 routing_ip()
 {
-  echo $(echo $1 | awk -F. '{print $1"."$2"."$3"."$4 + 127}')
+  echo $(echo $1 | @awk@ -F. '{print $1"."$2"."$3"."$4 + 127}')
 }
 
 
@@ -83,7 +83,7 @@
 router_ip=$(routing_ip "$ip")
 
 # Split the given IP/bits pair.
-vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
+vif_ip=`echo ${ip} | @awk@ -F/ '{print $1}'`
 
 hostname=dom$domid
 if [ "$vifid" != "1" ]
@@ -93,38 +93,38 @@
 
 dhcparg_remove_entry()
 {
-  local tmpfile=$(mktemp)
-  sed -e "s/${dev} //" "$dhcpd_arg_file" >"$tmpfile"
-  if ! diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
+  local tmpfile=$(@mktemp@)
+  @sed@ -e "s/${dev} //" "$dhcpd_arg_file" >"$tmpfile"
+  if ! @diff@ "$tmpfile" "$dhcpd_arg_file" >/dev/null
   then
-    cp "$tmpfile" "$dhcpd_arg_file"
+    @cp@ "$tmpfile" "$dhcpd_arg_file"
   fi
-  rm "$tmpfile"
+  @rm@ "$tmpfile"
 }
 
 dhcparg_add_entry()
 {
   dhcparg_remove_entry
-  local tmpfile=$(mktemp)
+  local tmpfile=$(@mktemp@)
   # handle Red Hat, SUSE, and Debian styles, with or without quotes
-  sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
-  sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
-  sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
-  rm -f "$tmpfile"
+  @sed@ -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \
+     "$dhcpd_arg_file" >"$tmpfile" && @cp@ "$tmpfile" "$dhcpd_arg_file"
+  @sed@ -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \
+     "$dhcpd_arg_file" >"$tmpfile" && @cp@ "$tmpfile" "$dhcpd_arg_file"
+  @sed@ -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \
+     "$dhcpd_arg_file" >"$tmpfile" && @cp@ "$tmpfile" "$dhcpd_arg_file"
+  @rm@ -f "$tmpfile"
 }
 
 dhcp_remove_entry()
 {
-  local tmpfile=$(mktemp)
-  grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
-  if ! diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
+  local tmpfile=$(@mktemp@)
+  @grep@ -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
+  if ! @diff@ "$tmpfile" "$dhcpd_conf_file" >/dev/null
   then
-    cp "$tmpfile" "$dhcpd_conf_file"
+    @cp@ "$tmpfile" "$dhcpd_conf_file"
   fi
-  rm "$tmpfile"
+  @rm@ "$tmpfile"
   dhcparg_remove_entry
 }
 
@@ -158,21 +158,21 @@
 
 case "$command" in
     online)
-        if ip route | grep -q "dev ${dev}"
+        if @ip@  route | @grep@ -q "dev ${dev}"
         then
           log debug "${dev} already up"
           exit 0
         fi
 
-        do_or_die ip link set dev "${dev}" up arp on
-        do_or_die ip addr add "$router_ip" dev "${dev}"
-        do_or_die ip route add "$vif_ip" dev "${dev}" src "$router_ip"
+        do_or_die @ip@ link set dev "${dev}" up arp on
+        do_or_die @ip@ addr add "$router_ip" dev "${dev}"
+        do_or_die @ip@ route add "$vif_ip" dev "${dev}" src "$router_ip"
         echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp
         [ "$dhcp" != 'no' ] && dhcp_up
         ;;
     offline)
         [ "$dhcp" != 'no' ] && dhcp_down
-        do_without_error ifconfig "${dev}" down
+        do_without_error @ifconfig@ "${dev}" down
         ;;
 esac
 
diff --git a/tools/hotplug/Linux/vif-openvswitch b/tools/hotplug/Linux/vif-openvswitch
index a8aea2acb5..a08b0b6628 100644
--- a/tools/hotplug/Linux/vif-openvswitch
+++ b/tools/hotplug/Linux/vif-openvswitch
@@ -24,15 +24,15 @@
 # rules for its ip addresses (if any).
 #============================================================================
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/vif-common.sh"
 
 check_tools()
 {
-    if ! command -v ovs-vsctl > /dev/null 2>&1; then
+    if ! command -v @ovs-vsctl@ > /dev/null 2>&1; then
         fatal "Unable to find ovs-vsctl tool"
     fi
-    if ! command -v ip > /dev/null 2>&1; then
+    if ! command -v @ip@ > /dev/null 2>&1; then
         fatal "Unable to find ip tool"
     fi
 }
@@ -79,10 +79,10 @@
 
     local vif_details="$(openvswitch_external_id_all $dev)"
 
-    do_or_die ovs-vsctl --timeout=30 \
+    do_or_die @ovs-vsctl@ --timeout=30 \
         -- --if-exists del-port $dev \
         -- add-port "$bridge" $dev $tag_arg $trunk_arg $vif_details
-    do_or_die ip link set $dev up
+    do_or_die @ip@ link set $dev up
 }
 
 case "$command" in
@@ -93,9 +93,9 @@
         ;;
 
     remove|offline)
-        do_without_error ovs-vsctl --timeout=30 \
+        do_without_error @ovs-vsctl@ --timeout=30 \
             -- --if-exists del-port $dev
-        do_without_error ip link set $dev down
+        do_without_error @ip@ link set $dev down
         ;;
 esac
 
diff --git a/tools/hotplug/Linux/vif-route b/tools/hotplug/Linux/vif-route
index 9cd417a005..98d67a8659 100755
--- a/tools/hotplug/Linux/vif-route
+++ b/tools/hotplug/Linux/vif-route
@@ -16,14 +16,14 @@
 #         this script).
 #============================================================================
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "${dir}/vif-common.sh"
 
 main_ip=$(dom0_ip)
 
 case "${command}" in
     add|online)
-        ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up
+        @ifconfig@ ${dev} ${main_ip} netmask 255.255.255.255 up
         echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp
         ipcmd='add'
         cmdprefix=''
@@ -50,7 +50,7 @@
 # If we've been given a list of IP addresses, then add routes from dom0 to
 # the guest using those addresses.
 for addr in ${ip} ; do
-    ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} metric ${metric}
+    ${cmdprefix} @ip@ route ${ipcmd} ${addr} dev ${dev} src ${main_ip} metric ${metric}
 done
 
 handle_iptable
diff --git a/tools/hotplug/Linux/vscsi b/tools/hotplug/Linux/vscsi
index 5ac26147ec..8f297e05df 100644
--- a/tools/hotplug/Linux/vscsi
+++ b/tools/hotplug/Linux/vscsi
@@ -4,7 +4,7 @@
 # Based on the block scripts code.
 #
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/xen-hotplug-common.sh"
 
 findCommand "$@"
diff --git a/tools/hotplug/Linux/xendomains.in b/tools/hotplug/Linux/xendomains.in
index 70f4129ef4..b066404b0d 100644
--- a/tools/hotplug/Linux/xendomains.in
+++ b/tools/hotplug/Linux/xendomains.in
@@ -150,13 +150,13 @@
     }
 fi
 
-if ! which usleep >&/dev/null
+if ! @which@ usleep >&/dev/null
 then
   usleep()
   {
     if [ -n "$1" ]
     then
-      sleep $(( $1 / 1000000 ))
+      @sleep@ $(( $1 / 1000000 ))
     fi
   }
 fi
@@ -170,7 +170,7 @@
 #
 contains_something()
 {
-  if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ]
+  if [ -d "$1" ] && [ `@ls@ $1 | wc -l` -gt 0 ]
   then
     return 0
   else
@@ -182,7 +182,7 @@
 rdname()
 {
     NM=$($CMD create --quiet --dryrun --defconfig "$1" |
-         sed -n 's/^.*(name \(.*\))$/\1/p;s/^.*"name": "\(.*\)",$/\1/p')
+         @sed@ -n 's/^.*(name \(.*\))$/\1/p;s/^.*"name": "\(.*\)",$/\1/p')
 }
 
 rdnames()
@@ -217,13 +217,13 @@
     if [[ "$1" =~ '(domain' ]] || [[ "$1" = "{" ]]; then
         name=;id=
     elif [[ "$1" =~ '(name' ]]; then
-        name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/')
+        name=$(echo $1 | @sed@ -e 's/^.*(name \(.*\))$/\1/')
     elif [[ "$1" =~ '(domid' ]]; then
-        id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/')
+        id=$(echo $1 | @sed@ -e 's/^.*(domid \(.*\))$/\1/')
     elif [[ "$1" =~ '"name":' ]]; then
-        name=$(echo $1 | sed -e 's/^.*"name": "\(.*\)",$/\1/')
+        name=$(echo $1 | @sed@ -e 's/^.*"name": "\(.*\)",$/\1/')
     elif [[ "$1" =~ '"domid":' ]]; then
-        id=$(echo $1 | sed -e 's/^.*"domid": \(.*\),$/\1/')
+        id=$(echo $1 | @sed@ -e 's/^.*"domid": \(.*\),$/\1/')
     fi
 
     [ -n "$name" -a -n "$id" ] && return 0 || return 1
@@ -244,7 +244,7 @@
 		RC=0
 		;;
 	esac
-    done < <($CMD list -l | grep "$LIST_GREP")
+    done < <($CMD list -l | @grep@ "$LIST_GREP")
     return $RC
 }
 
@@ -255,7 +255,7 @@
 	return;
     fi
 
-    mkdir -p $(dirname "$LOCKFILE")
+    @mkdir@ -p $(@dirname@ "$LOCKFILE")
     touch $LOCKFILE
 
     saved_domains=" "
@@ -266,7 +266,7 @@
 	saved_domains=`ls $XENDOMAINS_SAVE`
         for dom in $XENDOMAINS_SAVE/*; do
             if [ -f $dom ] ; then
-                HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
+                HEADER=`@head@ -c 16 $dom | @head@ -n 1 2> /dev/null`
                 if [ "$HEADER" = "$HEADCOMP" ]; then
                     echo -n " ${dom##*/}"
                     XMR=`$CMD restore $dom 2>&1 1>/dev/null`
@@ -277,7 +277,7 @@
                         echo -e '!'
                     else
                         # mv $dom ${dom%/*}/.${dom##*/}
-                        rm $dom
+                        @rm@ $dom
                     fi
                 fi
             fi
@@ -299,8 +299,8 @@
 	# restore correctly it requires administrative attention.
 	for dom in $XENDOMAINS_AUTO/*; do
 	    echo -n " ${dom##*/}"
-	    shortdom=$(echo $dom | sed -n 's/^.*\/\(.*\)$/\1/p')
-	    echo $saved_domains | grep -w $shortdom > /dev/null
+	    shortdom=$(echo $dom | @sed@ -n 's/^.*\/\(.*\)$/\1/p')
+	    echo $saved_domains | @grep@ -w $shortdom > /dev/null
 	    if [ $? -eq 0 ] || is_running $dom; then
 		echo -n "(skip)"
 	    else
@@ -328,7 +328,7 @@
 	if test "$state" != "-b---d" -a "$state" != "-----d"; then
 	    return 1;
 	fi
-    done < <($CMD list -l | grep "$LIST_GREP")
+    done < <($CMD list -l | @grep@ "$LIST_GREP")
     return 0
 }
 
@@ -345,16 +345,16 @@
     fi
 
     usleep 20000
-    for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
+    for no in `@seq@  0 $XENDOMAINS_STOP_MAXWAIT`; do
 	# exit if $CMD save/migrate/shutdown is finished
-	PSAX=`ps axlw | grep "$CMD $1" | grep -v grep`
+	PSAX=`ps axlw | @grep@ "$CMD $1" | @grep@ -v grep`
 	if test -z "$PSAX"; then exit; fi
 	if ! test -n "$3"; then echo -n '.'; fi
-	sleep 1
+	@sleep@ 1
 	# go to kill immediately if there's only zombies left
 	if all_zombies && test -n "$2"; then break; fi
     done
-    sleep 1
+    @sleep@ 1
     read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
     # kill $CMD $1
     kill $PSPID >/dev/null 2>&1
@@ -434,7 +434,7 @@
 	    echo -n "(save)"
 	    watchdog_xencmd save &
 	    WDOG_PID=$!
-	    mkdir -p "$XENDOMAINS_SAVE"
+	    @mkdir@ -p "$XENDOMAINS_SAVE"
 	    XMR=`$CMD save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
 	    if test $? -ne 0; then
 		echo -e "\nAn error occurred while saving domain:\n$XMR\n"
@@ -461,7 +461,7 @@
 	    fi
 	    kill $WDOG_PID >/dev/null 2>&1
 	fi
-    done < <($CMD list -l | grep "$LIST_GREP")
+    done < <($CMD list -l | @grep@ "$LIST_GREP")
 
     # NB. this shuts down ALL Xen domains (politely), not just the ones in
     # AUTODIR/*
@@ -482,7 +482,7 @@
     fi
 
     # Unconditionally delete lock file
-    rm -f $LOCKFILE
+    @rm@ -f $LOCKFILE
 
     exec 2>&3
 }
@@ -498,7 +498,7 @@
 		return 0
 		;;
 	esac
-    done < <($CMD list -l | grep "$LIST_GREP")
+    done < <($CMD list -l | @grep@ "$LIST_GREP")
     return 1
 }
 
@@ -531,7 +531,7 @@
     then
       return 0
     fi
-    missing=`/bin/ls $XENDOMAINS_SAVE`
+    missing=`@ls@ $XENDOMAINS_SAVE`
     echo -n " MISS SAVED: " $missing
     return 1
 }
diff --git a/tools/hotplug/Linux/xen-hotplug-common.sh.in b/tools/hotplug/Linux/xen-hotplug-common.sh.in
index 8c2cb9e25a..e9c64efcb0 100644
--- a/tools/hotplug/Linux/xen-hotplug-common.sh.in
+++ b/tools/hotplug/Linux/xen-hotplug-common.sh.in
@@ -14,7 +14,7 @@
 # License along with this library; If not, see <http://www.gnu.org/licenses/>.
 #
 
-dir=$(dirname "$0")
+dir=$(@dirname@ "$0")
 . "$dir/hotplugpath.sh"
 . "$dir/logging.sh"
 . "$dir/xen-script-common.sh"
@@ -25,7 +25,7 @@
 export PATH="${bindir}:${sbindir}:${LIBEXEC_BIN}:/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
 export LD_LIBRARY_PATH="${libdir}${LD_LIBRARY_PATH+:}$LD_LIBRARY_PATH"
 export LANG="POSIX"
-unset $(set | grep ^LC_ | cut -d= -f1)
+unset $(set | @grep@ ^LC_ | @cut@ -d= -f1)
 
 fatal() {
   _xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh
index 0150a4840e..c5a2bbe749 100644
--- a/tools/hotplug/Linux/xen-network-common.sh
+++ b/tools/hotplug/Linux/xen-network-common.sh
@@ -26,7 +26,7 @@
 #           that the virtual device will take once the physical device has
 #           been renamed.
 
-if ! which ifup >/dev/null 2>/dev/null
+if ! @which@ ifup >/dev/null 2>/dev/null
 then
   preiftransfer()
   {
@@ -83,16 +83,16 @@
     local dev="$1"
 
     # take interface down ...
-    ip link set dev ${dev} down
+    @ip@ link set dev ${dev} down
 
     # Initialise a dummy MAC address. We choose the numerically
     # largest non-broadcast address to prevent the address getting
     # stolen by an Ethernet bridge for STP purposes.
     # (FE:FF:FF:FF:FF:FF)
-    ip link set dev ${dev} address fe:ff:ff:ff:ff:ff || true
+    @ip@ link set dev ${dev} address fe:ff:ff:ff:ff:ff || true
 
     # ... and configure it
-    ip address flush dev ${dev}
+    @ip@ address flush dev ${dev}
 }
 
 # Usage: create_bridge bridge
@@ -101,12 +101,12 @@
 
     # Don't create the bridge if it already exists.
     if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then
-        if which brctl >&/dev/null; then
-            brctl addbr ${bridge}
-            brctl stp ${bridge} off
-            brctl setfd ${bridge} 0
+        if @which@ @brctl@ >&/dev/null; then
+            @brctl@ addbr ${bridge}
+            @brctl@ stp ${bridge} off
+            @brctl@ setfd ${bridge} 0
         else
-            ip link add name ${bridge} type bridge stp_state 0 forward_delay 0
+            @ip@ link add name ${bridge} type bridge stp_state 0 forward_delay 0
         fi
     fi
 }
@@ -119,31 +119,31 @@
     # Don't add $dev to $bridge if it's already on the bridge.
     if [ ! -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
         log debug "adding $dev to bridge $bridge"
-        if which brctl >&/dev/null; then
-            brctl addif ${bridge} ${dev}
+        if @which@ @brctl@ >&/dev/null; then
+            @brctl@ addif ${bridge} ${dev}
         else
-            ip link set ${dev} master ${bridge}
+            @ip@ link set ${dev} master ${bridge}
         fi
     else
         log debug "$dev already on bridge $bridge"
     fi
 
-    ip link set dev ${dev} up
+    @ip@ link set dev ${dev} up
 }
 
 remove_from_bridge () {
     local bridge=$1
     local dev=$2
 
-    do_without_error ip link set dev ${dev} down
+    do_without_error @ip@ link set dev ${dev} down
 
     # Don't remove $dev from $bridge if it's not on the bridge.
     if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
         log debug "removing $dev from bridge $bridge"
-        if which brctl >&/dev/null; then
-            do_without_error brctl delif ${bridge} ${dev}
+        if @which@ @brctl@ >&/dev/null; then
+            do_without_error @brctl@ delif ${bridge} ${dev}
         else
-            do_without_error ip link set ${dev} nomaster
+            do_without_error @ip@ link set ${dev} nomaster
         fi
     else
         log debug "$dev not on bridge $bridge"
@@ -161,7 +161,7 @@
     local mtu=$(xenstore_read_default "$XENBUS_PATH/mtu" "")
     if [ -z "$mtu" ]
     then
-        mtu="`ip link show dev ${bridge}| awk '/mtu/ { print $5 }'`"
+        mtu="`@ip@ link show dev ${bridge}| @awk@ '/mtu/ { print $5 }'`"
         if [ -n "$mtu" ]
         then
             log debug "$bridge MTU is $mtu"
@@ -170,7 +170,7 @@
     if [ -n "$mtu" ] && [ "$mtu" -gt 0 ]
     then
         log debug "setting $dev MTU to $mtu"
-        ip link set dev ${dev} mtu ${mtu} || :
+        @ip@ link set dev ${dev} mtu ${mtu} || :
 
         if [ ${type_if} = vif ]
         then
