Jim Meyering
2012-Jan-23 10:35 UTC
[Libguestfs] [PATCH] maint: use $var notation rather than ${var} when possible
I noticed some uses of ${srcdir} in shell scripts. That is almost always better written as $srcdir. The patch below converts most such variable references. Here are the few remaining candidates: $ git grep -i -E '\$\{[a-zA-Z_0-9]+\}'|grep -v Makefile.in.in configure.ac: JAR_INSTALL_DIR=\${prefix}/share/java configure.ac: JNI_INSTALL_DIR=\${libdir} debian/rules: for TEST in ${DEBIAN_SKIP_TEST}; do \ debian/rules:# mv $${mod} $$(dirname $${mod})/libguestfsmod.so; \ java/Makefile.am:libguestfs_jar_DATA = libguestfs-${VERSION}.jar java/Makefile.am:libguestfs-${VERSION}.jar: $(libguestfs_jar_class_files) perl/lib/Sys/Guestfs/Lib.pm: "-f", '${Package} ${Version} ${Architecture} ${Status}\n', perl/typemap: croak (\"${Package}::$func_name(): called on a closed handle\"); perl/typemap: croak (\"${Package}::$func_name(): $var is not a blessed HV reference\"); tests/data/Makefile.am: echo "$${i}abcdefghijklmnopqrstuvwxyz"; \ We could change all of those, too, except the ones in configure.ac and Makefile.am, since they refer to Make variables. Even those should be changed, but to use the preferred Makefile notation: $(prefix), $(libdir), $(VERSION).>From a86770ecd45666232a94d76c8725c8f9b1c76e3a Mon Sep 17 00:00:00 2001From: Jim Meyering <meyering at redhat.com> Date: Mon, 23 Jan 2012 11:15:12 +0100 Subject: [PATCH libguestfs] maint: use $var notation rather than ${var} when possible The only case to avoid in a shell script is when the byte after the "}" is word-constituent, and concatenating it would thus change the name of the variable. These changes were induced by running this command: git grep -l -i -E '\$\{(srcdir|md)' \ |xargs perl -pi -e 's/\$\{(srcdir|md)\}($|\w)/\$$1$2/gi' The "g" was needed because there was one line with two instances. The "i" is to handle ${SRCDIR}. The ($|\w) ensures that concatenating whatever follows the "}" won't change semantics. * gobject/run-bindtests: Use "$srcdir", not "${srcdir}". * haskell/run-bindtests: Likewise. * java/run-bindtests: Likewise. * ocaml/run-bindtests: Likewise. * perl/run-bindtests: Likewise. * python/run-bindtests: Likewise. * ruby/run-bindtests: Likewise. * tests/guests/guest-aux/make-debian-img.sh: Likewise, but $SRCDIR. * tests/guests/guest-aux/make-ubuntu-img.sh: Likewise. * tests/guests/guest-aux/make-windows-img.sh: Likewise. * tests/md/test-mdadm.sh: Likewise, but $md. --- gobject/run-bindtests | 2 +- haskell/run-bindtests | 2 +- java/run-bindtests | 2 +- ocaml/run-bindtests | 2 +- perl/run-bindtests | 2 +- python/run-bindtests | 4 ++-- ruby/run-bindtests | 4 ++-- tests/guests/guest-aux/make-debian-img.sh | 4 ++-- tests/guests/guest-aux/make-ubuntu-img.sh | 4 ++-- tests/guests/guest-aux/make-windows-img.sh | 6 +++--- tests/md/test-mdadm.sh | 4 ++-- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/gobject/run-bindtests b/gobject/run-bindtests index 48578cf..7691d6a 100755 --- a/gobject/run-bindtests +++ b/gobject/run-bindtests @@ -24,5 +24,5 @@ if [ -z "$GJS" ]; then fi ../run $GJS bindtests.js > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp ../run $GJS bindtests-manual.js 2>/dev/null diff --git a/haskell/run-bindtests b/haskell/run-bindtests index 3b17403..170b6d0 100755 --- a/haskell/run-bindtests +++ b/haskell/run-bindtests @@ -19,4 +19,4 @@ set -e ./Bindtests > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp diff --git a/java/run-bindtests b/java/run-bindtests index 4fc147a..9557c9d 100755 --- a/java/run-bindtests +++ b/java/run-bindtests @@ -19,4 +19,4 @@ set -e $JAVA -Djava.library.path=.libs Bindtests > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp diff --git a/ocaml/run-bindtests b/ocaml/run-bindtests index af6fc14..da10231 100755 --- a/ocaml/run-bindtests +++ b/ocaml/run-bindtests @@ -19,4 +19,4 @@ set -e ./bindtests > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp diff --git a/perl/run-bindtests b/perl/run-bindtests index 5a53ab6..e4621e3 100755 --- a/perl/run-bindtests +++ b/perl/run-bindtests @@ -20,4 +20,4 @@ set -e export PERL5LIB=$(pwd)/blib/lib:$(pwd)/blib/arch perl bindtests.pl > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp diff --git a/python/run-bindtests b/python/run-bindtests index 0299ff1..1a8ba76 100755 --- a/python/run-bindtests +++ b/python/run-bindtests @@ -18,5 +18,5 @@ set -e -$PYTHON ${srcdir}/bindtests.py > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +$PYTHON $srcdir/bindtests.py > bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp diff --git a/ruby/run-bindtests b/ruby/run-bindtests index aafcfba..e9fdc31 100755 --- a/ruby/run-bindtests +++ b/ruby/run-bindtests @@ -18,5 +18,5 @@ set -e -$RUBY -I${srcdir}/lib -Iext/guestfs ${srcdir}/bindtests.rb > bindtests.tmp -diff -u ${srcdir}/../bindtests bindtests.tmp +$RUBY -I$srcdir/lib -Iext/guestfs $srcdir/bindtests.rb > bindtests.tmp +diff -u $srcdir/../bindtests bindtests.tmp diff --git a/tests/guests/guest-aux/make-debian-img.sh b/tests/guests/guest-aux/make-debian-img.sh index b936f81..9449d0f 100755 --- a/tests/guests/guest-aux/make-debian-img.sh +++ b/tests/guests/guest-aux/make-debian-img.sh @@ -80,9 +80,9 @@ upload fstab.tmp /etc/fstab write /etc/debian_version "5.0.1" write /etc/hostname "debian.invalid" -upload ${SRCDIR}/guest-aux/debian-packages /var/lib/dpkg/status +upload $SRCDIR/guest-aux/debian-packages /var/lib/dpkg/status -upload ${SRCDIR}/../data/bin-x86_64-dynamic /bin/ls +upload $SRCDIR/../data/bin-x86_64-dynamic /bin/ls mkdir /boot/grub touch /boot/grub/grub.conf diff --git a/tests/guests/guest-aux/make-ubuntu-img.sh b/tests/guests/guest-aux/make-ubuntu-img.sh index e55c790..c2831aa 100755 --- a/tests/guests/guest-aux/make-ubuntu-img.sh +++ b/tests/guests/guest-aux/make-ubuntu-img.sh @@ -69,9 +69,9 @@ write /etc/debian_version "5.0.1" upload release.tmp /etc/lsb-release write /etc/hostname "ubuntu.invalid" -upload ${SRCDIR}/guest-aux/debian-packages /var/lib/dpkg/status +upload $SRCDIR/guest-aux/debian-packages /var/lib/dpkg/status -upload ${SRCDIR}/../data/bin-x86_64-dynamic /bin/ls +upload $SRCDIR/../data/bin-x86_64-dynamic /bin/ls mkdir /boot/grub touch /boot/grub/grub.conf diff --git a/tests/guests/guest-aux/make-windows-img.sh b/tests/guests/guest-aux/make-windows-img.sh index 47b8abb..ed94998 100755 --- a/tests/guests/guest-aux/make-windows-img.sh +++ b/tests/guests/guest-aux/make-windows-img.sh @@ -58,10 +58,10 @@ mkfs ntfs /dev/sda2 mount-options "" /dev/sda2 / mkdir-p /Windows/System32/Config -upload ${SRCDIR}/guest-aux/windows-software /Windows/System32/Config/SOFTWARE -upload ${SRCDIR}/guest-aux/windows-system /Windows/System32/Config/SYSTEM +upload $SRCDIR/guest-aux/windows-software /Windows/System32/Config/SOFTWARE +upload $SRCDIR/guest-aux/windows-system /Windows/System32/Config/SYSTEM -upload ${SRCDIR}/../data/bin-win32.exe /Windows/System32/cmd.exe +upload $SRCDIR/../data/bin-win32.exe /Windows/System32/cmd.exe mkdir "/Program Files" touch /autoexec.bat diff --git a/tests/md/test-mdadm.sh b/tests/md/test-mdadm.sh index e7f5775..620dcfd 100755 --- a/tests/md/test-mdadm.sh +++ b/tests/md/test-mdadm.sh @@ -100,7 +100,7 @@ eval `../../fish/guestfish --listen` ../../fish/guestfish --remote run for md in `../../fish/guestfish --remote list-md-devices`; do - ../../fish/guestfish --remote md-detail "${md}" > md-detail.out + ../../fish/guestfish --remote md-detail "$md" > md-detail.out sed 's/:\s*/=/' md-detail.out > md-detail.out.sh . md-detail.out.sh @@ -158,7 +158,7 @@ eval `../../fish/guestfish --listen` ../../fish/guestfish --remote run for md in `../../fish/guestfish --remote list-md-devices`; do - ../../fish/guestfish --remote md-stop "${md}" + ../../fish/guestfish --remote md-stop "$md" done ../../fish/guestfish --remote exit -- 1.7.9.rc2.2.g183d6
Possibly Parallel Threads
- [PATCH] out-of-tree build: ruby
- [PATCH] let the user explicitly choose ruby and rake programs
- [PATCH] Start adding return values tests for bindings
- [PATCH v6 3/3] gobject: Add outline guestfs-gobject(3) manual page.
- [PATCH] Fix dependencies on generator.ml