-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

  • 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? – siride Mar 27 '22 at 17:04

1 Answers1

0

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