Find the answer to your Linux question:
Results 1 to 3 of 3
I am trying to delete a file if it exists but I keep getting the following error: "[-f: not found [No such file or directory]" Is the syntax incorrect? Code: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    14

    ksh: checking if file exists


    I am trying to delete a file if it exists but I keep getting the following error:

    "[-f: not found [No such file or directory]"

    Is the syntax incorrect?

    Code:
    #!/bin/ksh
    
    FILE="/tmp/file.sh"
    
    if [-e $FILE]; then
       rm $FILE
    fi

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    You need to have a space after the '[' and before the ']'.

    Code:
    #!/bin/ksh
    
    FILE="/tmp/file.sh"
    
    if [ -e $FILE ]; then
       rm $FILE
    fi

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    14
    argh! Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •