[PATCH 09/16] t6000lib: tr portability fix

Subsystems: the rest

STALE3709d

7 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH 09/16] t6000lib: tr portability fix

From: Jeff King <hidden>
Date: 2016-06-15 22:44:22

Some versions of tr complain if the number of characters in
both sets isn't the same. So here we must manually expand
the dashes in set2.

Signed-off-by: Jeff King <redacted>
---
This almost makes me want to just use sed instead. But quoting that line
noise would probably make it less readable.

 t/t6000lib.sh |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/t/t6000lib.sh b/t/t6000lib.sh
index 180633e..b69f7c4 100755
--- a/t/t6000lib.sh
+++ b/t/t6000lib.sh
@@ -97,7 +97,10 @@ check_output()
 # from front and back.
 name_from_description()
 {
-        tr "'" '-' | tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//"
+        tr "'" '-' |
+		tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' \
+		   '------------------------------' |
+		tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//"
 }
 
 
-- 
1.5.4.4.543.g30fdd.dirty

[PATCH] t/t6000lib.sh: tr portability fix fix

From: Brandon Casey <hidden>
Date: 2016-06-15 22:44:23

Some versions of tr have a problem with character sets which begin with
multiple dashes and attempt to interpret them as long options. Use the
'--' notation to signal the end of command line options.

Signed-off-by: Brandon Casey <redacted>
---


Jeff King wrote:
Some versions of tr complain if the number of characters in
both sets isn't the same. So here we must manually expand
the dashes in set2.

Signed-off-by: Jeff King <redacted>
---
This almost makes me want to just use sed instead. But quoting that line
noise would probably make it less readable.
I get the following error on t6002-rev-list-bisect.sh:

*   ok 31: bisection diff --bisect u3 ^U <= 0
*   ok 32: bisection diff --bisect u4 ^U <= 0
*   ok 33: bisection diff --bisect u5 ^U <= 0
tr: unrecognized option `------------------------------'
Try `tr --help' for more information.
* FAIL 34: --bisect l5 ^root
        check_output  "git rev-list $_bisect_option l5 ^root"
tr: unrecognized option `------------------------------'
Try `tr --help' for more information.
* FAIL 35: --bisect l5 ^root ^c3
...


This is tr version 5.2.1.

This patch fixes things. If the dashdash notation is not portable, then
backslashing each dash also works. i.e. '\-\-\-\-.. etc. but as you
mentioned something like that is less readable, but possibly not as bad
as a sed version.

-brandon


 t/t6000lib.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t6000lib.sh b/t/t6000lib.sh
index b69f7c4..aac6a31 100755
--- a/t/t6000lib.sh
+++ b/t/t6000lib.sh
@@ -98,7 +98,7 @@ check_output()
 name_from_description()
 {
         tr "'" '-' |
-		tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' \
+		tr -- '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' \
 		   '------------------------------' |
 		tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//"
 }
-- 
1.5.4.4.481.g5075

Re: [PATCH] t/t6000lib.sh: tr portability fix fix

From: Jeff King <hidden>
Date: 2016-06-15 22:44:23

On Fri, Mar 14, 2008 at 03:47:37PM -0500, Brandon Casey wrote:
This patch fixes things. If the dashdash notation is not portable, then
backslashing each dash also works. i.e. '\-\-\-\-.. etc. but as you
mentioned something like that is less readable, but possibly not as bad
as a sed version.
It seems to work fine on Solaris with all versions of tr. I did just
blindly extend the '-' without thinking, though...I wonder if there are
systems that will get confused about it being a range. It might be
safer to just use sed anyway.

-Peff

Re: [PATCH] t/t6000lib.sh: tr portability fix fix

From: Brandon Casey <hidden>
Date: 2016-06-15 22:44:23

Jeff King wrote:
On Fri, Mar 14, 2008 at 03:47:37PM -0500, Brandon Casey wrote:
quoted
If the dashdash notation is not portable, then
backslashing each dash also works. i.e. '\-\-\-\-..
I wonder if there are
systems that will get confused about it being a range.
Oh, now I understand _why_ backslashing the dashes worked. When your
email arrived I was still trying to figure out why

  echo hello | tr aeiou '\-\-\-\-\-'

correctly converted the e and o into dashes. Because tr must have a
way for the user to escape the range notation. I don't use tr very
often.

-brandon

[PATCH] t/t6000lib.sh: tr portability fix fix

From: Brandon Casey <hidden>
Date: 2016-06-15 22:44:23

Some versions of tr have a problem with character sets which begin with
multiple dashes and attempt to interpret them as long options. Escape
each dash to avoid this confusion and also prevent a possible
interpretation of the dashes as a range.

Signed-off-by: Brandon Casey <redacted>
---

Jeff King wrote:
On Fri, Mar 14, 2008 at 03:47:37PM -0500, Brandon Casey wrote:
quoted
This patch fixes things. If the dashdash notation is not portable, then
backslashing each dash also works. i.e. '\-\-\-\-.. etc. but as you
mentioned something like that is less readable, but possibly not as bad
as a sed version.
It seems to work fine on Solaris with all versions of tr. I did just
blindly extend the '-' without thinking, though...I wonder if there are
systems that will get confused about it being a range. It might be
safer to just use sed anyway.
Here's the version with escaped dashes. If you do the sed version, it's
something to compare to for readability.

-brandon


 t/t6000lib.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t6000lib.sh b/t/t6000lib.sh
index b69f7c4..71f2140 100755
--- a/t/t6000lib.sh
+++ b/t/t6000lib.sh
@@ -99,7 +99,7 @@ name_from_description()
 {
         tr "'" '-' |
 		tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' \
-		   '------------------------------' |
+		   '\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-' |
 		tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//"
 }
 
-- 
1.5.4.4.481.g5075

Re: [PATCH] t/t6000lib.sh: tr portability fix fix

From: Jeff King <hidden>
Date: 2016-06-15 22:44:23

On Fri, Mar 14, 2008 at 04:26:31PM -0500, Brandon Casey wrote:
Here's the version with escaped dashes. If you do the sed version, it's
something to compare to for readability.

[...]

-		   '------------------------------' |
+		   '\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-' |
Ugh. How about:

  sed 'yA~`!@#$%^&*()_+={}[]|\;:"<>,/? A------------------------------A'

The 'A' delimiter is because in my test, Solaris sed didn't seem to
understand \/ to include the literal '/'. And all of the other
punctuation is already used in the pattern. ;)

-Peff

Re: [PATCH] t/t6000lib.sh: tr portability fix fix

From: Brandon Casey <hidden>
Date: 2016-06-15 22:44:23

Jeff King wrote:
On Fri, Mar 14, 2008 at 04:26:31PM -0500, Brandon Casey wrote:
quoted
Here's the version with escaped dashes. If you do the sed version, it's
something to compare to for readability.

[...]

-		   '------------------------------' |
+		   '\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-' |
Ugh. How about:

  sed 'yA~`!@#$%^&*()_+={}[]|\;:"<>,/? A------------------------------A'
Not working. I get:

*   ok 33: bisection diff --bisect u5 ^U <= 0
sed: -e expression #1, char 64: unterminated `y' command
* FAIL 34: --bisect l5 ^root
        check_output  "git rev-list $_bisect_option l5 ^root"
sed: -e expression #1, char 64: unterminated `y' command
* FAIL 35: --bisect l5 ^root ^c3
        check_output  "git rev-list $_bisect_option l5 ^root ^c3"
sed: -e expression #1, char 64: unterminated `y' command
* FAIL 36: --bisect l5 ^root ^c3 ^b4


But this does:

sed 'yA~`!@#$%^&*()_+={}\[]|\\;:"<>,/? A------------------------------A'

I have to escape open bracket and backslash on my end (linux). :(

Have to leave now, so if that doesn't work for you (which I'm thinking it
won't), I won't be able to test on my end for a while.

-brandon
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help