Bash substitute gives unexpected results (?)

Johnny Rosenberg gurus.knugum at gmail.com
Sun Apr 5 20:51:07 UTC 2015


2015-04-05 11:16 GMT+02:00 Nils Kassube <kassube at gmx.net>:

> Johnny Rosenberg wrote:
> > This is what I want. Everything except ”(” and ”–” (n-dash) should be
> > removed.
> > However, using pure Bash doesn't seem to work:
> >
> > $ a="Black Sand Beach (ブラック・サンド・ビーチ)"; echo ${a//[^(|–]}
> > (ブラック・サンド・ビーチ
> > $
> > Why does Bash consider n-dash and some Japanese characters the same?
>
> Maybe the three character encoding of your n-dash and the Japanese
> characters look similar enough to bash?
>
> > Is there a setting I need to do somehow?
>
> It has something to do with your locale settings. If you try the same
> with the default locale, the result is different. So I think you should
> set one of the LC_* shell variables (probably LC_COLLATE) to Japanese
> and try your command again.
>

Ok, the problem with that is that what's inside the parentheses isn't
always Japanese. Sometimes it's English, sometimes it's Russian and there
could be other languages as well. There could even be more than one
language. Maybe the easiest way is to stay with sed after all, since it
seems to work as expected.


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ



>
>
> Nils
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20150405/8ab82d0c/attachment.html>


More information about the ubuntu-users mailing list