plink and shell script

This is my shell script... test.sh

DIRECTORY=/XYZ/PQR
if [ -f $DIRECTORY/TTT/* ]; then
echo "In test.."
else
echo "lno.."
fi

when i run this script through a putty its output is:
./test.sh: line 2: [: too many arguments
lno..

But when i run the same script using plink its running fine and its output is as expected...

wanted to know why this is happening...

If the wildcard expands to more than one file, you will get that error.

Use a function instead:

is_file () 
{ 
    for f in "$@";
    do
        [ -f "$f" ] && return;
    done;
    return 1
}

if is_file "$DIRECTORY"/TTT/*; then
...

There there's something wrong with plink (whatever that is), or you are using it in a situation where the wildcard doesn't expand to more than one file.

There's no reason why a session invoked through putty should behave differently to one invoked through plink. That's very odd...

But as cfajohnson says, using [ -f * ] is generally something to avoid. What are you actually trying to test for?

Not generally: always.

Unless there is exactly one matching file, the result will always be wrong (a syntax error, or a false positive).

if i add the interperet explicitly then its working fine..

#!/bin/sh
DIRECTORY=/XYZ/PQR
if [ -f $DIRECTORY/TTT/* ]; then
echo "In test.."
else
echo "lno.."
fi

This works fine..are these shell dependent?i am using bash shell..

That will not work fine unless there is exactly one file that matches the pattern.

That is wrong in any and all shells.

Have you tried it on an empty directory?

Have you tried it on a directory containing more than one file?

If will also not be fine if $DIRECTORY contains whitespace.

See the is_file function I posted earlier.