help on awk---- need to assign the output of awk to a variable

hi i want to find the size of a folder and assign it to a variable and then compare if it is greater than 1 gb.

i am doin this script, but it is throwing error....

#!/bin/ksh

cd . | du -s | size = awk '{print $1}'

if size >= 112000

then 

echo size high

fi

ERROR :


size: awk: cannot open
size: {print $1}: cannot open
size: 112000: cannot open

can u help on it...

thanxs a lot in advance....!!!

cd . | du -s | size=$(awk '{print $1}')

Also:

  • note you need $size to reference the value of a variable.
  • why cd . ?
  • $high isn't set to anything.

hi carlo.... i have set $ now for all the variables....

after tht i am getting error as

./test[3]: =: cannot execute
./test[5]: 112000: not found

Make sure you have size=$(awk '{print $1}') - no $ when assigning size, and no spaces round the =.

@Nithz
In future posts, please post the current version of your script along with any matching error messages.
You are quite a long way adrift with syntax. Note that when assigning variables there is no space character either side of the equals sign.

This should get you past the syntax errors.

#!/bin/ksh
size=$(du -s | awk '{print $1}')
if [ ${size} -ge 112000 ]
then
        echo "${size} high"
fi

Now! I wonder where the number 112000 came from? The units of the output from "du -s" are in "512 byte blocks".
Using the unix in-line calculator "bc" I get a different value for the number of 512 byte chunks in a Gigabyte.

echo "(1024*1024*1024)/(512)"|bc
2097152

The units of "du -sk" are easier to work with. See the "man" page for "du".