I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the Bourne shell that I do not know about?

#! /bin/sh
if((test -e "$NAME"));then
echo File $NAME present
echo File $NAME not present

You don't need the enclosing parentheses, test itself would suffice:

if test -e "$NAME"; then

The (()) is for arithmetic comparison operations.

test is synonymous to [ command, so you can use:

if [ -e "$NAME" ]; then


Also some shell has the [[ keyword:

if [[ -e "$NAME" ]]; then
  • Thank you. That works for me. Is this only for test? Because I am able to do something like if(($# != 2));then....and the parentheses is required for me (or atleast it doesn't work without it). – Andrew M Mar 30 '16 at 3:27
  • @AndrewM Check my edits.. – heemayl Mar 30 '16 at 3:32
  • Thank you for the explanation. My book does not cover this well at all. – Andrew M Mar 30 '16 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.