Bug 33892 - --define deletes backslashes from the argument, but this is undocumented and useless
Summary: --define deletes backslashes from the argument, but this is undocumented and ...
Status: CLOSED NOTABUG
Alias: None
Product: Sisyphus
Classification: Development
Component: rpm (show other bugs)
Version: unstable
Hardware: all Linux
: P3 enhancement
Assignee: placeholder@altlinux.org
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-13 21:23 MSK by Ivan Zakharyaschev
Modified: 2017-11-16 23:06 MSK (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Zakharyaschev 2017-09-13 21:23:42 MSK
rpm --define unexpectedly deletes backslashes from the argument:

$ rpm --define="foobar 'an'" --showrc | fgrep foobar
 -8: foobar	'an'
$ rpm --define="foobar \'\a\n\'" --showrc | fgrep foobar
 -8: foobar	'an'
$ echo rpm --define="foobar \'\a\n\'" --showrc
rpm --define=foobar \'\a\n\' --showrc
$ rpm -q rpm
rpm-4.13.0.1-alt1.x86_64
$ 

Is this documented? What's the use of it?

To be more precise, it deletes a backslash and skips the next character:

$ echo rpm --define='foobar \\\\\a' --showrc
rpm --define=foobar \\\\\a --showrc
$ rpm --define='foobar \\\\\a' --showrc | fgrep foobar
 -8: foobar	\\a
$ 

The only use I can think of is escaping a space at the beginning:

$ rpm --define='foobar \ a' --showrc | fgrep foobar
 -8: foobar	 a
$ rpm --define='foobar a' --showrc | fgrep foobar
 -8: foobar	a
$
Comment 1 Ivan Zakharyaschev 2017-11-16 23:06:22 MSK
The use of the backslashes in rpm turns out to be there for multiline values. In spec:

%define foo a\
b

or in command line:

$ rpm --define 'foo a\
> b' --eval '%foo'
a
b
$ 

This means we need to escape backslashes and perhaps need a special tool to do this (in scripts). printf %q is an incorrect "overkill" because it does also other kinds of escaping/quoting. Perhaps something like: rpm --define "foo $(sed -e 's:\:\\:g' <<<"$VALUE")"

$ VALUE='a\b'
$ echo "$VALUE"
a\b
$ rpm --define "foo $(sed -e 's:\\:\\\\:g' <<<"$VALUE")" --eval '%foo'
a\b
$