autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assigning command output to a variable


From: Eric Blake
Subject: Re: Assigning command output to a variable
Date: Mon, 19 Nov 2012 11:36:01 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2

On 11/19/2012 10:09 AM, Adam Mercer wrote:
> Hi
> 
> For one of my projects I need to get the contents of
> /etc/redhat-release during the configure process and assign the
> contents to a variable. I'm currently using the following:
> 
>     redhat_release=`cat /etc/redhat-release 2> /dev/null`
> 
> This works fine, but I was wondering if anyone had any better suggestions?

You can avoid the command substitution fork by using read:

{ read redhat_release < /etc/redhat-release; } 2>/dev/null

Whether that's deemed any simpler, though, is a matter of taste.  Not to
mention that use of 'read' like this is limited to cases where you know
you are reading a one-line file (when present).

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]