test: argument expected

I'm newbie to coding script so i found test: argument expected when i run it. please help me

a=`df -k |awk '{print $5 }'|egrep "(100%|[89][0-9]%)"|cut -d"%" -f1|tail -1`
if [ $a -ne "" ]
then
df -k|egrep "(100%|[89][0-9]%)"|awk '{print $1,$5,$6}'
else
echo "No disk capacity more than 80%"
fi

thk in advance

Try:
if [ "$a" -ne "" ]

It's work !!! thank a lot sir

The -ne operator is an arithmetic operator, for string comparison the != operator must be used.

if [ "$a"!= "" ]

You can also use the -n operator:

if [ -n "$a" ]

Jean-Pierre.

if [ "$a" -ne "" ]
is legal. It will be true if $a is a non-zero integer. You're right that the user probably meant to use "!=" here. It seems to be working because the output is constrained to an integer greater than 80.

Now that I'm awake, I see a second problem as well. Some filesystems based on the McKusick filesystem have a minfree parameter which reserves disk space that can never be allocated except by root. 100% is often reported when the non-reserved soace has been exhausted. At this point, a non-root user cannot allocate any more space. However, a root process can continue to allocate space and this drives the number reported by df above 100%.

df output may vary between platforms. On Solaris with nawk you can write something like this:

df -k|nawk 'NR>1{sub(/%/,"",$5)
		if($5>=80)
			(x[$1]=$5)&&c=1
  }END{
 	if(c)
		for(i in x) print i,x
	else 
		print "No disk capacity more than 80%"}'

on Linux like this:

df -P|awk 'NR>1{sub(/%/,"",$5)
	if($5>=80)
		(x[$6]=$5)&&c=1
  }END{
 	if(c)
		for(i in x) print i,x
	else 
		print "No disk capacity more than 80%"}'

no need for a 'sub(/%/,"",$5)':

	if(int($5)>=80)

or for some awk-s:

	if($5+0>=80)

Why? int is better?

Anyway,
I'd go further with my own solution:

df -k|nawk '{sub(/%/,"",$5)}
		NR>1&&$5>=80{c=1;print $1,$5
 }END{ 
	if (c!=1)
		print "No disk capacity more than 80%"}'
df -P|awk '{sub(/%/,"",$5)}
	NR>1&&$5>=80{c=1;print $6,$5
 }END{ 
	if (c!=1)
		print "No disk capacity more than 80%"}'

And if I wanted to avoid the usage of sub here, I'd have written it like this:

df -k|nawk '
NR>1&&$5>=80{c=1;print $1,$5
 }END{ 
if (c!=1)
print "No disk capacity more than 80%" }' FS="[ %]*"
df -P|awk '
NR>1&&$5>=80{c=1;print $6,$5
 }END{ 
if (c!=1)
print "No disk capacity more than 80%" }' FS="[ %]*"