user1553248
user1553248

Reputation: 1204

writing a shell script if statement to check for directory

I need to write a script that will recreate my opt folder if it gets deleted when I remove a package from it. Here's a link to my previous post: dpkg remove to stop processes

Now, the issue I'm running into could be better described here: http://lists.debian.org/debian-devel/2006/03/msg00242.html

I was thinking of just adding a postrem script which checks if an opt directory exists, and if not, creates one. My experience with shell scripts is pretty limited though..

Upvotes: 0

Views: 351

Answers (1)

We Are All Monica
We Are All Monica

Reputation: 13336

[ -d "$dir" ] || mkdir -p "$dir"

This could be written more verbosely / clearly as:

if ! test -d "$dir"; then
    mkdir -p "$dir"
fi

See help test for more information.

Upvotes: 1

Related Questions