nabik
nabik

Reputation: 65

`--pattern=regex` option in less behave unexpectedly

I have a file a.txt,

one two
two one

my goal is to match the 'one' that is at the end of the sentence.

if it is opened in less (less a.txt) , and manually searched by regex (/one$), as expected, it will match the 'one' in second line.

However if it is opened with,
less --pattern='one$' a.txt,
opened file will match the both 'one's.

I also tried less '+/one$' a.txt, which resulted in same outcome.

Upvotes: 2

Views: 28

Answers (1)

that other guy
that other guy

Reputation: 123470

This behavior appears to be due to $ acting as a terminator/separator in the LESS environment variable, leaking into option parsing:

Some options like -k or -D require a string to follow the option letter. The string for that option is considered to end when a dollar sign ($) is found. For example, you can set two -D options like this:

 LESS="Dn9.1$Ds4.1"

You can tell by the way you can specify one option inside another using $. The following ignores the one because it gets overwritten by a -ptwo:

less --pattern='one$ptwo' a.txt

Upvotes: 1

Related Questions