Re: Extracting Values to Variables in BASH

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/22/04


Date: Sat, 22 May 2004 08:27:51 -0500


Dr. Lince M. Lawrence wrote:
> I am new in writing BASH/shell script and I want to add a condition
> for
> excessive file size. So I write, for instance:
>
> a=`du <filename>`
> echo=$a
>
> I get the answer 6280 <filename>
>
> Now I wanna get the first set of value (ie only the file size), to my
> variable, without doing an external computation to extract it.
>
> Thanks,
> Dr. Lince M Lawrence

a=`du <filename>`
echo "${a% *}"

The white-space is a single tab character.

        Ed.



Relevant Pages