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

Re: Extract substring from cat



On Fri, Oct 16, 2015 at 02:15:46PM +0200, Alfred Charles Stockton wrote:
> 
> If I issue the command cat /etc/*-release on my Debian system I get:-
> 
> PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
> NAME="Debian GNU/Linux"
> VERSION_ID="8"
> VERSION="8 (jessie)"
> ID=debian
> HOME_URL="http://www.debian.org/";
> SUPPORT_URL="http://www.debian.org/support/";
> BUG_REPORT_URL="https://bugs.debian.org/";
> 
> Now what I would like to do is to only print the substring "Debian
> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
> 
> Please tell me how I should go about this?

The EASY way? "( source /etc/*-release; echo $PRETTY_NAME )".

'source' executes the commands in the file(s) which, in this case, are 
simple variable assignments. 'echo' prints the contents of one of those 
variables. Finally "( ... ; ... )" executes the two commands one after 
the other in a subshell. When the subshell exits (after the echo 
command), the variables will be forgotten.

> 
> --
> Regards,
> Alf Stockton
> 
> 

-- 
For more information, please reread.

Attachment: signature.asc
Description: PGP signature


Reply to: