Skip to content

How to expand possibly non-existent user constructed variable name? #3411

Answered by mlschroe
voxik asked this question in Q&A
Discussion options

You must be logged in to vote

You just need to escape the first % in the expand macro:

rpm -D "name string-io" -D "string_io_prerelease .dev" --eval "%{expand:%%{?%{gsub %{name} - _}_prerelease}}"
.dev

Without the expand:

$ rpm -D "name string-io" -D "string_io_prerelease .dev" --eval "%%{?%{gsub %{name} - _}_prerelease}"
%{?string_io_prerelease}
$ rpm -D "name string-io" -D "string_io_prerelease .dev" --eval "%{?%{gsub %{name} - _}_prerelease}"
$

As you can see, the expand macro does not get anything to expand if you do not escape the %.

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@voxik
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by voxik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants