Tidy up the shell scripts somewhat.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 25 Jun 2013 19:29:36 +0000 (20:29 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 25 Jun 2013 19:29:36 +0000 (20:29 +0100)
Main changes are replacing `sed' calls with ${var#...} and ${var%...},
and improving the quoting.

confsubst.in
findlinks.in
maninst
mdw-setup
mklinks.in

index 285e031..f9ba37b 100755 (executable)
@@ -78,8 +78,7 @@ for fixup; do
     *?=*) ;;
     *) echo >&2 "$0: bad substitution: $fixup"; exit 1 ;;
   esac
-  tag=$(echo "$fixup" | sed 's/=.*$//') && \
-  value=$(echo "$fixup" | sed 's/^[^=]*=//') && \
+  tag=${fixup%%=*} value=${fixup#*=}
   subst="$subst s\a@$tag@\a$value\ag;"
 done
 
index 2790b92..fbbcd98 100755 (executable)
@@ -59,7 +59,6 @@ done
 ###--------------------------------------------------------------------------
 ### Read the names of all the files I support.
 ###
-###
 ### Yes, this is ugly and hacky: well spotted.  Shells have a nasty habit of
 ### spontaneously forking when redirection gets too hard for them to think
 ### about, so instead of something nice along the lines of
@@ -74,14 +73,14 @@ done
 ### the pattern match in the `case' below work properly.
 
 files=$(
-  files=""
+  files=:
   find "$pkgdatadir" -type f -print | {
     while read name; do
-      files="$files:$(echo "$name" | sed 's;^.*/;;')"
+      files="$files${name##*/}:"
     done
-    echo $files
+    echo "$files"
   }
-):
+)
 
 ###--------------------------------------------------------------------------
 ### Now examine the current directory.
@@ -90,13 +89,13 @@ files=$(
 ### say `findlinks >.links' without any problems.
 
 find . \( -type f -o -type l \) -print | while read name; do
-  base="$(echo "$name" | sed 's;^.*/;;')"
+  base=${name##*/}
   case "$files" in
-    *:$base:*)
-      echo $name
+    *:"$base":*)
+      echo "${name#./}"
       ;;
     *)
   esac
-done | sed 's,^\./,,' | sort
+done | sort
 
 ###----- That's all, folks --------------------------------------------------
diff --git a/maninst b/maninst
index cb238c5..25ea78d 100755 (executable)
--- a/maninst
+++ b/maninst
@@ -24,8 +24,7 @@ case $op in
   *) echo >&2 "$0: unknown operation \`$1'"; exit 1 ;;
 esac
 for i; do
-  base=`echo "$i" | sed 's:^.*/::'`
-  sec=`echo "$base" | sed 's:^.*\.::'`
+  base=${i##*/} src=${base##*.}
   case $op in
     install)
       echo -n " Installing manpage $base$ext"
index ab62f09..e4513e0 100755 (executable)
--- a/mdw-setup
+++ b/mdw-setup
@@ -29,7 +29,7 @@ set -e
 ###--------------------------------------------------------------------------
 ### Basic setup stuff.
 
-ego=$(echo "$0" | sed 's:^.*[/\\]::; s:\.*$::')
+ego=${0##*[/\\]}; ego=${ego%%.*}
 usage="Usage: $ego"
 
 ###--------------------------------------------------------------------------
@@ -78,7 +78,7 @@ done
 if [ "$configure" ]; then
   grep >/dev/null AM_PROG_LIBTOOL $configure && libtoolize -f
   find . -name Makefile.m4 -print | while read m4; do
-    dir=$(echo $m4 | sed 's:/[^/]*$::')
+    dir=${m4%/*}
     (cd $dir &&
      m4 Makefile.m4 >Makefile.am.new &&
      mv Makefile.am.new Makefile.am)
index fd126f2..863ead7 100755 (executable)
@@ -71,8 +71,8 @@ done
 
 [ $# = 0 ] && set .links
 cat "$@" | while read name; do
-  base="$(echo $name | sed 's:^.*/::')"
-  dir="$(echo $name | sed 's:^[^/]:./&:; s:/[^/]*$::')"
+  case "$name" in "" | "#"*) continue ;; esac
+  base=${name##*/} dir=${name%/*}
   if [ -r "$pkgdatadir/$base" ]; then
     mkdir -p "$dir"
     rm -f "$name"