[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function
From: |
Jim Meyering |
Subject: |
Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function |
Date: |
Mon, 20 Jun 2011 10:03:20 +0200 |
Voelker, Bernhard wrote:
> why not re-using the same function, i.e. why not retire w2_?
> btw: isn't head -1 deprecated use?
Thanks for mentioning it. That usage is actually officially obsolete, now.
The trouble is that "head -1" is more portable than "head -n1", so
I'll replace it with sed 1q. See below.
> warn_ ()
> {
> # If IFS does not start with ' ', set it and emit the warning in a subshell.
> case $IFS in
> ' '*) printf '%s\n' "$*" >&2
> test $stderr_fileno_ = 2 \
> || { printf '%s\n' "$*" | head -n 1 >&$stderr_fileno_ ; } ;;
> *) (IFS=' '; warn_ "$@");;
> esac
> }
Good idea. Thanks!
Your name is on the following, so I'll wait for your ACK.
I used your email address from THANKS.
Let me know if you'd prefer a different one.
>From b970f0a50546e7cc062b0f76df45ae69661b2846 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Mon, 20 Jun 2011 09:46:06 +0200
Subject: [PATCH] tests: improve init.sh by removing w2_
* tests/init.sh (w2_): Remove, moving contents into...
(warn_): ...here. Call self from subshell when IFS must be changed.
---
tests/init.sh | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/tests/init.sh b/tests/init.sh
index b857730..5878179 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -74,19 +74,18 @@ Exit () { set +e; (exit $1); exit $1; }
# the reason for skip/failure to console, rather than to the .log files.
: ${stderr_fileno_=2}
-# Call w2_ only via warn_, since correct expansion of "$*" depends on
-# IFS starting with ' '. Always write the full diagnostic to stderr.
+# Note that correct expansion of "$*" depends on IFS starting with ' '.
+# Always write the full diagnostic to stderr.
# When stderr_fileno_ is not 2, also emit the first line of the
# diagnostic to that file descriptor.
-w2_ () { printf '%s\n' "$*" >&2
- test $stderr_fileno_ = 2 \
- || { printf '%s\n' "$*" | head -1 >&$stderr_fileno_ ; } ; }
warn_ ()
{
# If IFS does not start with ' ', set it and emit the warning in a subshell.
case $IFS in
- ' '*) w2_ "$@";;
- *) (IFS=' '; w2_ "$@");;
+ ' '*) printf '%s\n' "$*" >&2
+ test $stderr_fileno_ = 2 \
+ || { printf '%s\n' "$*" | head -1 >&$stderr_fileno_ ; } ;;
+ *) (IFS=' '; warn_ "$@");;
esac
}
fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
--
1.7.6.rc2.9.g58b6a
>From 1d919fbb7fc5e75e3bf2835f9e2fccbe179b7d69 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 20 Jun 2011 10:01:43 +0200
Subject: [PATCH] tests: init.sh: use "sed 1q" in place of "head -1"
* tests/init.sh (warn_): Use "sed 1q" in place of "head -1".
The latter is officially obsolete but more portable than "head -n1".
Reported by Bernhard Voelker.
---
tests/init.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/init.sh b/tests/init.sh
index 5878179..460937d 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -84,7 +84,7 @@ warn_ ()
case $IFS in
' '*) printf '%s\n' "$*" >&2
test $stderr_fileno_ = 2 \
- || { printf '%s\n' "$*" | head -1 >&$stderr_fileno_ ; } ;;
+ || { printf '%s\n' "$*" | sed 1q >&$stderr_fileno_ ; } ;;
*) (IFS=' '; warn_ "$@");;
esac
}
--
1.7.6.rc2.9.g58b6a
- [PATCH] tests: use printf, not echo in init.sh's warn_ function, Jim Meyering, 2011/06/14
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Eric Blake, 2011/06/14
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Jim Meyering, 2011/06/14
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function, James Youngman, 2011/06/14
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Jim Meyering, 2011/06/15
- RE: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Voelker, Bernhard, 2011/06/16
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Jim Meyering, 2011/06/16
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Jim Meyering, 2011/06/17
- RE: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Voelker, Bernhard, 2011/06/20
- Re: [PATCH] tests: use printf, not echo in init.sh's warn_ function,
Jim Meyering <=
- RE: [PATCH] tests: use printf, not echo in init.sh's warn_ function, Voelker, Bernhard, 2011/06/20