From: Rakesh Sharma on 3 Apr 2010 20:32 Hi, I want to match a string of numbers followed optionally by either a + or a -. The corner cases are: the number cannot begin with a 0 unless it's a solitary 0. So expressing this in terms of regular expressions I can write: [0][+-]? | [1-9][0-9]*[+-]? So far so good, but how would I write the equivalent functionality in terms of shell file patterns of the kind found in the 'case'..'esac' statments of bourne shell? Thanks -- Rakesh
From: marty.mcgowan on 3 Apr 2010 20:48 On Apr 3, 8:32 pm, Rakesh Sharma <sharma...(a)hotmail.com> wrote: > Hi, > > I want to match a string of numbers followed optionally by either a + > or a -. > The corner cases are: the number cannot begin with a 0 unless it's a > solitary 0. > > So expressing this in terms of regular expressions I can write: > > [0][+-]? | [1-9][0-9]*[+-]? > > So far so good, but how would I write the equivalent functionality in > terms > of shell file patterns of the kind found in the 'case'..'esac' > statments of bourne shell? > > Thanks > > -- Rakesh does this do it in bourne; i'm using bash: case $1 in 0[+-]|[1-9][0-9]*[+-]) echo pattern -- $1;; *) echo NOT a match: $1;; esac -=+-- Marty McG
From: Rakesh Sharma on 3 Apr 2010 20:57 On Apr 4, 5:48 am, "marty.mcgo...(a)gmail.com" <marty.mcgo...(a)gmail.com> wrote: > On Apr 3, 8:32 pm, Rakesh Sharma <sharma...(a)hotmail.com> wrote: > > > > > Hi, > > > I want to match a string of numbers followed optionally by either a + > > or a -. > > The corner cases are: the number cannot begin with a 0 unless it's a > > solitary 0. > > > So expressing this in terms of regular expressions I can write: > > > [0][+-]? | [1-9][0-9]*[+-]? > > > So far so good, but how would I write the equivalent functionality in > > terms > > of shell file patterns of the kind found in the 'case'..'esac' > > statments of bourne shell? > > > Thanks > > > -- Rakesh > > does this do it in bourne; i'm using bash: > > case $1 in > 0[+-]|[1-9][0-9]*[+-]) echo pattern -- $1;; > *) echo NOT a match: $1;; > esac > > -=+-- Marty McG No, this does not work under the bourne shell. What I need is the filename wildcards to accomplish this thingy. Regards, -- Rakesh
From: Seebs on 3 Apr 2010 22:05 On 2010-04-04, Rakesh Sharma <sharma__r(a)hotmail.com> wrote: > So far so good, but how would I write the equivalent functionality in > terms > of shell file patterns of the kind found in the 'case'..'esac' > statments of bourne shell? You can't. Shell patterns don't have a way to express repetition of anything other than "any character". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Ben Bacarisse on 3 Apr 2010 22:14 Rakesh Sharma <sharma__r(a)hotmail.com> writes: > I want to match a string of numbers followed optionally by either a + > or a -. > The corner cases are: the number cannot begin with a 0 unless it's a > solitary 0. > > So expressing this in terms of regular expressions I can write: > > [0][+-]? | [1-9][0-9]*[+-]? [0] is little odd! You can make the ending more clear by re-writing this as: (0|[1-9][0-9]*)[+-]? > So far so good, but how would I write the equivalent functionality in > terms > of shell file patterns of the kind found in the 'case'..'esac' > statments of bourne shell? bash can but not a POSIX shell. You can get close if can limit the number of digits by simply writing out all the cases, but you can't even use [0-9] (you need [0123456789] instead) so the end result will be horrid and error prone. -- Ben.
|
Next
|
Last
Pages: 1 2 Prev: bash: how to transfer some non-ascii code Next: very strange ksh behavior |