Skip to main content
Tweeted twitter.com/StackUnix/status/939319854208872448

How can I create a Bash: condition conditional script, based on program execution resultsoutput from a command?

Source Link
Mary
  • 165
  • 1
  • 8

Bash: condition based on program execution results

I have a Java program that gets two arguments (a video file name and an image) and outputs a boolean (0 or 1) in the first line:

java -jar myProgram video1.mp4 image.png
> 0
>some extra information...
>other extra information....going on

Now using bash script, I need to iterate through all files in a folder (not files in nested folders), run the program with the file name passed to the first argument (video name changes everytime, and image is fixed), and if the output in the first line is 0, copy the file in folder0, and if the output is 1, copy the file to folder1.

How can I achieve that in bash?