1

I'm trying to add a new repository to my Fedora and was asked to introduce the following command:

su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm' 

I'm trying to understand what every part of the command means, and almost have it all, except for the line $(rpm -E %fedora). I googled it but found nothing, so I decided to ask here.

2 Answers 2

3

It runs the command rpm -E %fedora and substitutes its output from stdout into the outer command.

rpm -E evaluates the variable(s) in the text passed to it.

2
  • I see, so it returns the version of Fedora I am running. Thanks. Commented Dec 26, 2013 at 2:49
  • 1
    $() is a better version of the increasingly deprecated `` subshell notation. Commented Dec 26, 2013 at 3:29
1

RPM Macros

When you have questions like this it's best to consult the man pages. Take a look at the rpm man page.

$ man rpm ... -E, --eval='EXPR' Prints macro expansion of EXPR. 

Realizing that %fedora is a macro if you go a bit further down in the rpm man page you can see what files provide macro definitions.

Macro Configuration /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros 

Taking a peek inside of /etc/rpm/macros will reveal this definition.

$ grep fedora /etc/rpm/macros* /etc/rpm/macros.dist:%fedora 19 

So we can see that there is a definition called %fedora and on my system (Fedora 19) it has a value of "19".

Inline command execution

The notation $(..) will execute whatever command is between the parenthesis and substitute the returned results in their place.

Example

$ echo $(echo hi) hi 

Or in your case:

$ echo $(rpm -E %fedora) 19 

Putting it all together

So when the command you're asking about runs the following things happen. A RPM macro, %fedora is evaluated using the rpm command. That command is executed in line. Once expanded to "19" that value is used within the larger yum command to install the appropriate .rpm file for a given version of Fedora.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.