V
V
Vadim Aliev2021-11-03 18:47:55
linux
Vadim Aliev, 2021-11-03 18:47:55

How to determine if a directory exists?

Good day to all! Sorry for such questions, I'm new to this. There is a script that takes a directory name as an argument and displays a message - if there is such a directory. The script itself:

#!/bin/bash

if  ; then
    echo 'exists'
else
    echo 'not exists'
fi


use case

[email protected]:/home/redfern89# ./test vhd
not exists


but, no matter what I specify, it always says that the directory does not exist, although I specify an existing one. The same thing is displayed when I specify a non-existing one. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pvsam, 2021-11-11
@pvsam

You have two square brackets, you need one, try it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question