Unix Shell - Extracting Values to Variables in BASH

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2004 > Extracting Values to Variables in BASH





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Extracting Values to Variables in BASH
Dr. Lince M. Lawrence

2004-05-22, 10:28 pm

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
Bob

2004-05-22, 10:28 pm

On Sat, 22 May 2004 05:05:30 -0700, 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.
>


set `du <filename>`
echo $1



Ed Morton

2004-05-22, 10:28 pm



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.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com