test: argument expected

+ [ -e /etc/passwd ]
test.sh: test: argument expected

#!/bin/bash
if [ -e /etc/passwd ]
then
echo thennnn
else
echo elseeee
fi

why does it show this error? Clearly from debug mode, the argument is passed. I also tried if [ -e "/etc/passwd" ]

Run on Solaris 9.
Thanks

Worked fine for me ...

+ '[' -e /etc/passwd ']'
+ echo thennnn
thennnn

you might look at

if test -e /etc/passwd; then ...

Yes I have been written this kind of code for a hundred scripts but I dont know it shows errors this time...Is it something about the shell in Solaris but I tried both ksh and bash; it gave the same error. I am sure that if test -e /etc/passwd would work.

Please help..
Thanks a lot

you have a script called "test.sh" in your path... this script expects an argument...

My code is so basic as it is exactly as below called test.sh
#!/bin/bash
if [ -e /etc/passwd ]
then
echo thennnn
else
echo elseeee
fi

I run it by calling sh test.sh or sh -x test.sh. What is the argument that this script expects as you said?

Thank you

I think he means ./test.sh. As there might be some PATH issue and you have another copy of a test.sh elsewhere

which -a test.sh

thats what i thought about... another script in your path with the same name...

I tried sh ./test.sh. it showed the same error.

if [ -f /etc/passwd ] works fine. So the question is down to why doesn't -e work?

Thanks again

Odd, a non-regular file "ls -l /etc/passwd" should have something differerent from a "-" for the first character (osx/darwin style /private/etc/ type setup?), but at least its not a script problem now :wink:

       -e FILE
              FILE exists

       -f FILE
              FILE exists and is a regular file

The -e option to test(1) is not very portable!

According to the Solaris 10 man page for test(1), the -e option is not available for sh(1)