KItis
KItis

Reputation: 5626

What does this script means

I am new to scripting and I found following expression in a script.

if [ -d $_path ];then

could someone help me to understand what does -d $_path means inside if statement?

Thanks in advance for any help.

Upvotes: 1

Views: 360

Answers (3)

huon
huon

Reputation: 102056

It checks whether the value of _path is a directory. Note that _path is a variable and the $ is the get-value-of operation (sort of); it is not looking for a folder called $_path.

As an example:

> mkdir dir
> touch file
> ls
dir/  file
> _path=dir    # set the variable `_path`
> if [ -d $_path ]; then echo yes; else echo no; fi
yes
> _path=file
> if [ -d $_path ]; then echo yes; else echo no; fi
no

Upvotes: 1

acraig5075
acraig5075

Reputation: 10756

It's a test for whether _path is a directory.

Note bash and DOS are two entirely different things.

Upvotes: 2

Anders Lindahl
Anders Lindahl

Reputation: 42870

From man test:

-d FILE
    FILE exists and is a directory

Upvotes: 3

Related Questions