0

I have a command:

dwebp /home/user/1/input.webp -o /home/user/2/output.png

What should I add to execute this command only if input.webp exists?

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
Nikolay Shen
  • 31
  • 1
  • 6
  • The question has already beenn answered [here](https://stackoverflow.com/questions/669675/how-can-i-check-a-file-exists-and-execute-a-command-if-not) – Arturo Seijas Oct 17 '18 at 14:23
  • @ArturoSeijas that link is not the answer, there's no clear explanation on how to run it the other way around (i.e. if the file DOES exist). I was confused and reached here, so yeah... the question is still pretty relevant – DARKGuy Jun 10 '20 at 22:27

1 Answers1

0

You can create a script that validates that, and executes the command only if that file exists in the filesystem.

#!/usr/bin/bash

if [ -f /home/user/1/input.webp ]; then
   dwebp /home/user/1/input.webp -o /home/user/2/output.png
fi
mjuarez
  • 15,479
  • 10
  • 55
  • 70