bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: case modification won't work with pattern


From: Chris F.A. Johnson
Subject: Re: case modification won't work with pattern
Date: Thu, 10 Mar 2011 22:56:27 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Thu, 10 Mar 2011, Chet Ramey wrote:

On 3/10/11 9:04 PM, Clark J. Wang wrote:
On Thu, Mar 10, 2011 at 9:31 PM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:

On Thu, Mar 10, 2011 at 10:22:12AM +0800, Jerry Wang wrote:
      var="abcabc"
      echo "var: ${var}"
      echo "replace the leading \"ab\" to uppercase: ${var^ab}" # expect
to get "ABcabc" ?

The documentation is a bit terse, admittedly.


Agree. Almost all of the poeple around me don't understand why it works that
way. Maybe some background of the feature requirement can help us to
understand better.

The original requests were for a way to change the first letter or
every letter to uppercase or lowercase, like ksh typeset -l/-u, using
word expansion syntax (one request was for a new builtin command to
do it).  That's what you get if you don't use the pattern part of the
expansion.  I invented the pattern following the case specifier to allow
each character to be separately modified.

  I suggested using parameter expansion with patterns in
  <http://lists.gnu.org/archive/html/bug-bash/2006-02/msg00020.html>:

$ foo=bar
$ echo ${foo^}  ## Convert first character
Bar
$ echo ${foo^^}  ## Convert all characters
BAR
$ echo ${foo^[a-m]} ## Convert first character that matches pattern
Bar
$ echo ${foo^^[a-m]} ## Convert all characters that match pattern
BAr

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]