(patch for Bash) more ${var|...} expansions
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Sun May 8 02:22:16 UTC 2005
Here are few parameter expansions that I added to ${var|...} notation:
${var|.strip}
Strip leading/trailing whitespaces, and collapse consecutive
whitespaces into one space. Same as `echo $var`.
${var|.upper}
${var|.lower}
${var|.swapcase}
Convert to uppercase or lowercase, or toggle the case.
${var|.capitalize}
Convert the first char to uppercase, and the rest to lowercase.
${var|.rev}
Flip strings, like rev(1).
Idea for the above came from Python string methods. So, you can do
a='abC 123'
echo "${a|.strip}" --> 'abC 123'
echo "${a|.upper}" --> 'ABC 123'
echo "${a|.lower}" --> 'abc 123'
echo "${a|.swapcase}" --> 'ABc 123'
echo "${a|.capitalize}" --> 'Abc 123'
echo "${a|.rev}" --> '321 Cba'
Also, added
${var|-regex}
Remove all matching 'regex' pattern. Comparable to ${var//glob}.
${var|+regex}
Return only the matching 'regex' pattern.
So, you can delete or extract 'regex' from string, ie.
a='abC 123'
echo "${a|-[a-z]}" --> 'C 123'
echo "${a|+[a-z]}" --> 'ab'
Ref:
http://freshmeat.net/projects/bashdiff/
http://home.eol.ca/~parkw/index.html#bash
Enjoy...
--
William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
Slackware Linux -- because it works.
--
William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
Slackware Linux -- because it works.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list