init.sh: improve portability and efficiency
authorJim Meyering <meyering@redhat.com>
Sat, 13 Feb 2010 14:51:37 +0000 (15:51 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 16 Feb 2010 06:33:32 +0000 (07:33 +0100)
* tests/init.sh (find_exe_basenames_): Remove unnecessary use of
"dummy" in a for loop.
Use '!', not '^' to select the complement of a character set used
in a "case" statement.
Use shell variable manipulation, a la ${...%.exe}, rather than sed.
Suggestions from Eric Blake.

tests/init.sh

index cb1ab03..02f53c8 100644 (file)
@@ -102,12 +102,13 @@ find_exe_basenames_()
   feb_fail_=0
   feb_result_=
   feb_sp_=
-  for feb_file_ in $feb_dir_/*.exe dummy; do
+  for feb_file_ in $feb_dir_/*.exe; do
     case $feb_file_ in
-      dummy) continue;;
-      *[^-a-zA-Z/0-9_.+]*) feb_fail_=1; break;;
-      *) feb_file_=$(echo $feb_file_ | sed "s,^$feb_dir_/,,;"'s/\.exe$//')
-        feb_result_="$feb_result_$feb_sp_$feb_file_";;
+      *[!-a-zA-Z/0-9_.+]*) feb_fail_=1; break;;
+      *) # Remove leading file name components as well as the .exe suffix.
+         feb_file_=${feb_file_##*/}
+         feb_file_=${feb_file_%.exe}
+         feb_result_="$feb_result_$feb_sp_$feb_file_";;
     esac
     feb_sp_=' '
   done
@@ -129,7 +130,7 @@ create_exe_shim_functions_()
   esac
 
   base_names_=$(find_exe_basenames_ $1) \
-    || { echo "$0 (exe-shim): skipping directory: $1" 1>&2; return 1; }
+    || { echo "$0 (exe_shim): skipping directory: $1" 1>&2; return 1; }
 
   if test -n "$base_names_"; then
     for base_ in $base_names_; do