Need shell scripters to test Bash patch
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Fri Jan 9 22:56:28 UTC 2004
On Fri, Jan 09, 2004 at 10:54:38AM -0500, John Wildberger wrote:
> On January 8, 2004 02:29 pm, William Park wrote:
>
> > But, I do use regular expression aweful lot, both in conditional test
> > and in splitting/extracting strings. And, Bash source is better for
> > patching. I mean, Zsh source is true spaghetti. :-)
> Forgive my ignorance, but could you plese explain how nto go about to use your
> patch to add to bash? I would be keen to play with it.
> What are the steps involved?
> John
To compile,
wget ftp://.../bash-2.05b.tar.gz --> Bash source tarball
wget http://home.eol.ca/~parkw/bash.diff --> my patch
tar -xzf bash-2.05b.tar.gz
mv bash-2.05b bash
cd bash
patch -p1 < ../bash.diff
CFLAGS="-DPATTERN_MATCHING" ./configure
make
strip bash
./bash
--> Now you are in my Bash shell.
exit
--> back to your original shell.
To make it your login shell,
cp bash /usr/local/bin
echo /usr/local/bin/bash >> /etc/shells
chsh -s /usr/local/bin/bash loginname
Now, some of usage...
1. help case
help for
help match
help array
help arrayfilter --> it's Python thing.
help arraymap --> it's Python thing.
help read
help echo
2. Regular expression operators =~ and !~ will work in all conditional
tests, ie.
[ string =~ regex ]
[[ string =~ regex ]]
test string =~ regex
They are all implemented through my builtin command
match string regex
Eg.
[ abc123 =~ '([a-z][0-9])' ] && array SUBMATCH
[[ abc123 =~ '[a-z]+' ]] && array SUBMATCH
[[ abc123 =~ '([0-9]+)' ]] && array SUBMATCH
3. Regular expression case statement. Shell normally expects glob
pattern, ie.
case "..." in
glob_pattern) ... ;;
...
esac
So, to trigger regex, put matching single/double quotes as the first
and the last character of the pattern. Eg.
abc*) --> glob
abc\*) --> glob
abc*[0-9]) --> glob
'abc') --> regex
''abc'') --> regex
'abc.*[0-9]') --> regex
4. Array is the big one. The most useful features are splitting and
extracting regex from string, ie. -e and -v option. In fact, this
is what got me started.
a=()
array -e '[a-z]+' a abc123xyz789 && array a --> abc xyz
array -e '[0-9]+' a abc123xyz789 && array a --> abc xyz 123 789
a=()
array -v '_+' a abc__123_xyz__789 && array a --> abc 123 xyz 789
array -v '[a-z_]+' a abc__123_xyz__789 && array a --> abc 123 xyz 789 123 789
-j option would be useful for cutting like 'cut' but with string not
just a character. Eg.
b="$a"
array -j '..' b && array b --> abc..123..xyz..789..123..789
b=()
array -j '..1' b $a && array b --> abc 23..xyz..789 23..789
-f option is for fixed width fields, like Awk's FIXEDWIDTHS. Eg.
a=()
array -f 3,4 a 1234567890 && array a --> 123 4567
-s and -r option are for sorting and reversing the array. Eg.
array -s a
array -r a
--
William Park, Open Geometry Consulting, <opengeometry-FFYn/CNdgSA at public.gmane.org>
Linux solution for data management and processing.
--
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