Csh is complaining about the % at the end of the numbers in the expression. Removing them from the df output and from your hard coded assignment will fix.
#!/usr/bin/env tcsh
#script check size files systems
set x = `df -h /usr | tail -n1 | awk '{ print( $5+0 ); }'` # add +0 to have awk convert to integer
set y = 60
if ($x >= $y) then
echo "BAD"
else
echo "GOOD"
endif
You are doing string comparison with this syntax in either bash or Korn shells (and I believe that you need [[ and ]] to use ==). With string comparison you have to be careful as you might not get what you expect. Consider the statement where the variables evaluate to something like this:
if [[ 0040% > 30% ]]
Written this way, the expression will evaluate to false, not true as you might expect.
If you use the (deprecated) form with 'gt' instead of '>' to force a numeric comparison
if [[ 0040% -gt 30% ]]
you will get an error: 40%: more tokens expected
If you wrote the if statement in ksh/bash using the current standard it would also fail if the variables evaluate to a string with a trailing %:
x=60%
y=50%
if (( $x > $y ))
then
echo "true"
else
echo "false"
fi
running this in ksh yields: line 6: 60% > 50% : arithmetic syntax error.
$ cat whichsame
#!/bin/tcsh
set a="$1"
set b="$2"
if ( `echo $a | cut -d'%' -f2` == `echo $b | cut -d'%' -f2` ) then
echo same
else
echo not same
endif