Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh-ify a bash script



On Thu, Jan 20, 2022 at 10:31:21AM -0800, Bart Schaefer wrote:
> On Thu, Jan 20, 2022 at 3:26 AM Andreas Kusalananda Kähäri
> <andreas.kahari@xxxxxx> wrote:
> >
> > grep -Fwo -e zsfree -e zerr -e subst -- Src/**/*.c |
> 
> I think "grep -w" doesn't work for the original problem because of the
> ".*SOCK_STREAM" in one of the search terms.

Sorry for going off-topic... but...

The -w option is just a convenience thing to not have to insert one of
\b, \< \>, or [[:<:]] [[:>:]] at either end of the pattern.

Removing the -F is what needs to be done for the patterns to be treated
as BREs.

Compare

	man zsh | grep -w 'as\>.*\<an'

(2 lines of output, each of which has the word "as" followed by the word
"an"),

	man zsh | grep -w 'as.*an'

(7 lines of output, since "an" may match at start of word and "an" at
the end, as on a line with "as ... than"), and

	man zsh | grep 'as.*an'

(15 lines of output due to matching things like "basename ... command")

What the OP may want to do is to change their expression

	socketpair.*SOCK_STREAM

into

	socketpair\>.*\<SOCK_STREAM

and then use -w with grep, depending on what it is they want to actually
match, and what word boundary pattern(s) their regular expression
libraries support.


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.




Messages sorted by: Reverse Date, Date, Thread, Author