djhaskin987
djhaskin987

Reputation: 10057

Give RPM macro an argument with spaces

Example RPM macro:

%define hello() \
    printf 'hello, %{1}.\\n';

I would like to be able to give it macros with spaces in it, as in:

%{hello "Dak Tyson"}

->

printf 'hello, Dak Tyson.\n'

However, it keeps doing this:

%{hello "Dak Tyson"}

->

printf 'hello, "Dak.\n'

In other words, it doesn't interpret the double quotes, but uses them as-is.

Single quotes don't work either:

%{hello 'Dak Tyson'}

->

printf 'hello, 'Dak\.\n'

Nor backslashes:

%{hello Dak\ Tyson}

->

printf 'hello, Dak\.\n'

Nor braces:

%{hello {Dak Tyson}}

->

printf 'hello, {Dak.\n'

Is there any way to give an RPM macro arguments with spaces?

Upvotes: 3

Views: 1792

Answers (2)

mavit
mavit

Reputation: 639

Since RPM 4.14, there has been a quote macro. Using your example,

%{hello %{quote:Dak Tyson}}

Upvotes: 1

djhaskin987
djhaskin987

Reputation: 10057

I trawled through the RPM API C code having to do with macro expansion. I found a loop in there which uses spaces to parse out the arguments and (I think) there is no way around this loop. I don't think you can give arguments with spaces.

I did find that macro arguments are safe, though.

My .rpmmacros file:

%hello() '%{1}'
%name Dak Tyson

With the above macros defined, This command:

rpm --eval '%{hello %{name}}'

yields:

'Dak Tyson'

So that if I really needed spaces in my macros definitions, I can define them as macros first.

I also found, incidentally, that nested parameterized macros don't work.

This command:

rpm --eval '%{hello %{hello name}}'

yields:

error: Unterminated {: {hello
  2<     (empty)
  1<   (empty)
  0< '
'

Upvotes: 4

Related Questions