Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

shell script question ..... regarding file size test

SOLVED
Go to Solution
Highlighted

shell script question ..... regarding file size test

I am trying to test the size(greater than zero) of a file in "c" shell.(HPUX11)
If it is greater than zero bytes .... I want to send and email to abc ..... if it is zero bytes I want to email def.
Here is the test I am doing and I am getting a "if: Badly formed number." error and the script halts.
Can anyone tell me where I am going wrong?

if (-s /directsm/errors.txt) then
elm -s EDI_ERROR abc@abc.com < /directsm/errors.txt
else
elm -s $SHIPPERFILE def@abc.com < $TDFFILE
endif
Will assign points for solutions!!
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

Re: shell script question ..... regarding file size test

csh is not as robust as ksh or posix sh. Is their a reason you are doing this in csh?

The "-s" is not a valid csh selection. You could use "-z" to test for zero instead.

if ( -z /directsm/errors.txt ) then
elm ...
else
elm ...
endif

HTH

-- Rod Hills
There be dragons...
5 REPLIES
Honored Contributor Honored Contributor

Re: shell script question ..... regarding file size test

I think it needs to be brackets and spaces so:

if [ -s /directsm/errors.txt ]
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
HPE Pro

Re: shell script question ..... regarding file size test

Hi Daniel,

Try:

if [ -s /directsm/errors.txt ]
then
...
fi

Regards,

Dave
Honored Contributor Honored Contributor

Re: shell script question ..... regarding file size test

csh is not as robust as ksh or posix sh. Is their a reason you are doing this in csh?

The "-s" is not a valid csh selection. You could use "-z" to test for zero instead.

if ( -z /directsm/errors.txt ) then
elm ...
else
elm ...
endif

HTH

-- Rod Hills
There be dragons...

Re: shell script question ..... regarding file size test

Thanks Rodney ..... that solved the problem.
I was getting very strange errors trying to use the -s with the c shell.
Can I ask you where you found out that the -s was not valid with the c shell?
Will assign points for solutions!!
Honored Contributor Honored Contributor

Re: shell script question ..... regarding file size test

Do a "man csh" and look for section on "expressions". It lists what is allowed in a csh expresssion.

HTH

-- Rod Hills
There be dragons...