When I wrote shell script to downlowd corpus, I need to chekc if the directory I want to make exists.

I found it, for practice of shell script I will organize it in here.

1
2
3
4
if [ -d $LINK_OF_DIR ]; then 
    if [ -L $LINK_OF_DIR ]; then
    fi
fi

The above code checks whether or not $LINK_OF_DIR exists and is symbolic link.

the below is to check if $LINK_OF_DIR is directory.

So if a directory with the name exists, if statement returns false

1
2
3
if [ -d $LINK_OF_DIR ]; then 
......
fi

The follow is to check if $LINK_OF_DIR is symbolic link.

1
2
3
4
...
    if [ -L $LINK_OF_DIR ]; then
    fi
...

Reference