Subject: [alpine-devel] Busybox diff / grep oddities

From: Jeff Pohlmeyer <[email-masked]>
Date: Fri, 22 Aug 2014 08:33:18 -0500

Recursive diff succeeds without trying?
  busybox diff -rq /bin /etc
  echo $?

This should be a match?
  echo "abbc" |  busybox grep 'ab\+c'

 - Jeff

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Der Tiger <[email-masked]>
Date: Fri, 22 Aug 2014 17:21:20 +0200

Hi Jeff,
>   busybox diff -rq /bin /etc
Actually, it does what it's supposed to do with BusyBox 1.21.1 on Alpine
2.7.9.

|  $ diff -rq /bin /etc||
||  Only in /etc: TZ||
||  Only in /bin: addgroup||
||  Only in /bin: adduser||
||  Only in /etc: adjtime||
||  Only in /etc: alpine-release||
||  Only in /bin: ash||
||  [...]||
||  $ echo $?||
||  1||
|
>   echo "abbc" |  busybox grep 'ab\+c'
A very peculiar behaviour, indeed. Though, syntax and match are correct,
because:

  "In  basic  regular  expressions the metacharacters ?, +, {, |, (, and )
  lose their special meaning; instead use the backslashed versions \?,
  \+, \{, \|, \(, and \)."

For more information see: http://unixhelp.ed.ac.uk/CGI/man-cgi?grep

I've verified the behaviour with GNU grep 2.18, as well. Your example is
equivalent to:

|  echo "abbc" | grep 'abb*c'||
|
HIH, Tiger

---

From: Timo Teras <[email-masked]>
Date: Sat, 23 Aug 2014 00:49:05 +0300

On Fri, 22 Aug 2014 17:21:20 +0200
Der Tiger <[email-masked]> wrote:

> Actually, it does what it's supposed to do with BusyBox 1.21.1 on
> Alpine 2.7.9.
> 
> |  $ diff -rq /bin /etc||
> ||  Only in /etc: TZ||

Not sure about this... but.

> A very peculiar behaviour, indeed. Though, syntax and match are
> correct, because:
> 
>   "In  basic  regular  expressions the metacharacters ?, +, {, |, (,
> and ) lose their special meaning; instead use the backslashed
> versions \?, \+, \{, \|, \(, and \)."
> 
> 
> I've verified the behaviour with GNU grep 2.18, as well. Your example
> is equivalent to:
> 

Alpine 3.0+ use musl implementation of regular expressions in busybox.
musl is strictly POSIX confirming, and \+ in BRE is not POSIX
specified. Some implementations support it, notable GNU. But that is
implementation specific extension and not portable or standard
compliant.

The posix compliant way is:

$ echo "abbc" | busybox grep "ab\{1,\}c"
abbc

See, eg. http://www.regular-expressions.info/posix.html

/Timo

---

---

From: Der Tiger <[email-masked]>
Date: Sat, 23 Aug 2014 00:18:02 +0200

> Not sure about this... but.
The given example works with BusyBox 1.22.1 on 3.0.1 just as well.

> Alpine 3.0+ use musl implementation of regular expressions in busybox.
There we go: grep 'ab\+c' certainly fails on 3.0, while grep 'abb*c' is
POSIX and therefore working fine.

Tiger

---

---

From: Timo Teras <[email-masked]>
Date: Sat, 23 Aug 2014 01:33:26 +0300

On Sat, 23 Aug 2014 00:18:02 +0200

> The given example works with BusyBox 1.22.1 on 3.0.1 just as well.

Yes. And is broken in edge. Seems stat() returns different stuff. Not
sure if it's kernel, musl or busybox bug, but it is a bug.

- Timo

---