jeudi 17 décembre 2015

Trying with piping commands into an if statement

I have a script that puts a bunch of command to make a directory into a text file. Then it cats the file into sh to run the commands.

What I am trying to do is only run the command if the directory doesn't already exist.

Here is what I have:

A text file with something like this:

  • mkdir /path/to/a/directory
  • mkdir /path/to/another/directory
  • mkdir /path/to/yet/another/directory

Note: there are no bullets in the text file I just added them to help readability.

In my script I have a line like this

cat /path/to/my/file.txt | sh

But is there a way to do something like this:

cat /path/to/my/file.txt | if path already exists then go to the next, if not | sh

In other words I would like the skip the attempt to make the directory if the path already exists.

I am running linux and the script is in bash.

I hope this makes sense, and as always thanks in advance for any help!

Aucun commentaire:

Enregistrer un commentaire