Bug 1254837

Summary: typo in /etc/profile.d/less.sh
Product: Red Hat Enterprise Linux 6 Reporter: Frank Hirtz <fhirtz>
Component: lessAssignee: Pavel Raiskup <praiskup>
Status: CLOSED NOTABUG QA Contact: Miroslav Hradílek <mhradile>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.7CC: fhirtz, hhorak, mhradile, omerusta, praiskup, sardella
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-09 05:20:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1269194    
Attachments:
Description Flags
Patch for less.sh for Fedora Rawhide none

Description Frank Hirtz 2015-08-19 01:54:58 UTC
What problem/issue/behavior are you having trouble with?  What do you expect to see?

Observed behaviour with a non-redhat "less", on RHEL6.7 (less-436-13.el6.x86_64):

$ less testfile >/dev/null
/bin/ksh: syntax error at line 1: `|' unexpected

This is due to the following change made to /etc/profile.d/less.sh:

<snip>
@@ -1,2 +1,2 @@
 # less initialization script (sh)
-[ -x /usr/bin/lesspipe.sh ] && export LESSOPEN="|/usr/bin/lesspipe.sh %s"
+[ -x /usr/bin/lesspipe.sh ] && export LESSOPEN="${LESSOPEN-||/usr/bin/lesspipe.sh %s}"
</snip>

The double '||' is an error / a typo, it needs to be a single '|' character there.

I can't say why it doesn't appear to affect the current stock "less" binary for RHEL5/RHEL6/RHEL7, but it does affect pretty much all others (try the RHEL5 'less' on RHEL6, to reproduce the error). Even an older RHEL6 less binary (from RHEL6.2) produces the error.

Steps to Reproduce:

1) Confirm current version:
[fmhirtz@ivanova bin]$ rpm -q less
less-436-13.el6_6.sjis.1.x86_64

2) Grab older version and get 'less' binary to test:

[fmhirtz@ivanova less]$ rpm2cpio ../less-436-4.el6.sjis.1.x86_64.rpm > less.cpio
[fmhirtz@ivanova less]$ cpio -i --make-directories < less.cpio 
397 blocks
[fmhirtz@ivanova less]$ cd usr/bin/
[fmhirtz@ivanova bin]$ ls
less  lessecho  lesskey  lesspipe.sh

3) Test older binary:
[fmhirtz@ivanova bin]$ ./less lesspipe.sh 
/bin/bash: -c: line 0: syntax error near unexpected token `|'
/bin/bash: -c: line 0: `|/usr/bin/lesspipe.sh lesspipe.sh'

Actual results:

/bin/ksh: syntax error at line 1: `|' unexpected

Expected results:

No error.

Comment 1 Frank Hirtz 2015-08-19 02:03:31 UTC
This was apparently introduced specifically as a fix in:

https://rhn.redhat.com/errata/RHBA-2014-0755.html

<snip>
* Previously, the lesspipe script returned incorrect exit status codes. As a
consequence, the less utility failed to decompress empty files that had been
compressed with the gzip utility, and an unwanted message was displayed. With
this update, a pipe character ("|") has been added in front of the LESSOPEN
environment variable to enforce a new default behavior of lesspipe. For backward
compatibility, lesspipe has the same behavior if LESSOPEN remains unchanged. As
a result, the less utility now detects and displays empty files correctly.
(BZ#615303)
</snip>

...but as a side-effect, now this breaks any environment where there's more than one version of 'less' present.

Comment 2 Viktor Jancik 2015-09-02 12:58:46 UTC
The double '||' is not a bug. It modifies the way less handles exit statuses from LESSOPEN scripts. Specifically, it maintains the original behavior (prior a change) for backwards compatibility with older LESSOPEN scripts.

As the bug is reported against RHEL 6.7, I don't think we should modify this behavior, as many currently running RHEL 6.7 could be using old LESSOPEN scripts.

I did however make the change in F22 and up.

Comment 3 Ömer Fadıl Usta 2015-09-03 10:58:44 UTC
(In reply to Viktor Jancik from comment #2)
> 
> I did however make the change in F22 and up.

Nope after trying to fix bug in less.sh in Fedora Rawhide made another typo.
Now we need to apply following patch which i will upload here

Comment 4 Ömer Fadıl Usta 2015-09-03 11:00:41 UTC
Created attachment 1069748 [details]
Patch for less.sh for Fedora Rawhide

This is fixing the """ /etc/profile.d/less.sh:[:2: too many arguments
  """ bug

Comment 5 Viktor Jancik 2015-09-03 11:25:47 UTC
Yes, I fixed that yesterday as the first report appeared. Sorry for the typo.

Comment 6 Ömer Fadıl Usta 2015-11-04 22:35:29 UTC
Is this bug still exist ?

Comment 7 Frank Hirtz 2016-01-04 15:14:56 UTC
The upstream fix works fine (tested on F23), is this something that'd be possible to change in RHEL? I know that there were concerns with behavioral changes in the area previously.

Comment 15 Pavel Raiskup 2016-04-25 04:46:49 UTC
The '||' syntax is used intentionally.  The $LESSOPEN variable points to
script which might exit with non-zero exit status -- and using the '||'
syntax guarantees that less will react on the status correctly.

If there is installed non-default 'less' program reacting on the same
configuration (environment variable) - the non-default 'less' program should
be updated to newer version >= v451.

If it is somehow important to run older less program, feel free to install
additional profile.d script which will set the LESSOPEN variable
unconditionally, or use the '~/.bash_profile' or equivalent shell init script.

Comment 16 Fedora Update System 2016-04-25 05:06:51 UTC
less-481-5.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2016-9a937faae1

Comment 17 Fedora Update System 2016-04-25 06:07:18 UTC
less-481-5.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2016-ff70f6b6a3

Comment 18 Fedora Update System 2016-04-25 17:50:59 UTC
less-481-5.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-9a937faae1

Comment 19 Fedora Update System 2016-04-26 00:52:43 UTC
less-481-5.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-ff70f6b6a3

Comment 20 Fedora Update System 2016-04-26 20:53:11 UTC
less-481-5.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.

Comment 21 Fedora Update System 2016-05-07 11:55:28 UTC
less-481-5.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.