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
  • 349,597
  • 67
  • 533
  • 578
Nikolay Shen
  • 31
  • 1
  • 7
  • 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

1

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
  • 16,372
  • 11
  • 56
  • 73