Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
I see, so it returns the version of Fedora I am running. Thanks. –  Sal Manning Dec 26 '13 at 2:49
1  
$() is a better version of the increasingly deprecated `` subshell notation. –  DopeGhoti Dec 26 '13 at 3:29

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.