Bug 1293690

Summary: Misbehavior when regexp isn't defined
Product: [Fedora] Fedora Reporter: Jakub Prokes <jprokes>
Component: sedAssignee: Petr Stodulka <pstodulk>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 23CC: hhorak, jpacner, pbonzini, pstodulk
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-03-24 22:32:28 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:

Description Jakub Prokes 2015-12-22 17:17:57 UTC
Description of problem:
When in replace command (s) isn't defined and address is defined by regexp, then sed use address regexp for replacing.

Version-Release number of selected component (if applicable):
sed (GNU sed) 4.2.2
sed-4.2.2-11.fc23.x86_64

How reproducible:
echo -e "foo\nbar" | sed '/o/s//X/'

Actual results:
fXo
bar

Expected results:
sed: -e expression #1, char 0: no previous regular expression

Additional info:
[jprokes@patejl Wallpapers ]$ echo -e "foo\nbar" | sed '/o/s//X/'
fXo
bar
[jprokes@patejl Wallpapers ]$ echo -e "foo\nbar" | sed '1s//X/'
sed: -e expression #1, char 0: no previous regular expression

When I compare these two commands, its behavior is inconsistent and possibly dangerous, in cases when sed is used inside larger bash script.

Comment 1 Paolo Bonzini 2016-03-24 22:32:28 UTC
// is defined to be the last regular expression that was used by the script.  In the case of /o/s//X/, the last regular expression to be tried before executing s//X/ was the address.