-1

How can you check if the directory exists using a while loop in bash? In general, words what I want is while true if directory exists to do something

1
  • Sounds like you've got the gist. Have you looked at some basic bash syntax guides to see if you can turn your pseudocode into bash? Commented Mar 27, 2022 at 17:04

1 Answer 1

1

You can use the following construct to check if a folder (with name $dirname) exists:

[ -d $dirname ]

This will exit successfully if the folder exists, allowing for the following code:

[-d $dirname ] && echo "exists" || echo "does not exist"

or

if [ -d $dirname ]; then
    echo "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.