Blue42
Blue42

Reputation: 139

Could someone explain to me what is happening in this shell script?

I understand that its going to a directory and recursively and forcefully removing ./tmp. My issue is with the "-d ./tmp". What does the -d do and why would the "./" be in front of tmp?

Thanks in advance

cd $WORKING_DIR

if [ -d ./tmp}; then
       rm -rf ./tmp
fi

Upvotes: 0

Views: 30

Answers (1)

fedorqui
fedorqui

Reputation: 289725

It checks whether ./tmp exists and is a directory. In that case, it removes it.

From man test:

-d FILE

FILE exists and is a directory


By the way, the syntax has errors:

if [ -d ./tmp}; then
             ^
             needs space and ] instead of }

Correctly:

if [ -d ./tmp ]; then

Upvotes: 1

Related Questions