2

i made a linux script which receives as first argument a path to a directory. I don't know the path. And i want to check if "file.txt" exists at that certain path . For example :

if [ -e $1/file.txt ];then
       echo HAHA
fi
2
  • 1
    [[ -f "$1/file.txt" ]] && echo "HAHA" should work. Commented Nov 22, 2013 at 15:36
  • What you have should work as intended as long as $1 doesn't contain any whitespace. Quoting it as "$1/file.txt" would take care of that problem. Commented Nov 22, 2013 at 17:01

1 Answer 1

4
if [[ -e "$1/file.txt" ]]; then
       echo "It exists"
fi
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.