I'm running a script to compare images but want the script to do things based on the level of difference. How on earth so I assign the output of the compare command to a variable, and if possible convert it to an integer (rounded or truncated, it doesn't really matter)? So far I have tried various syntax for treating it like a normal operation. None have worked.
I'm running a Linux terminal window on Ubuntu 14.04
I have tried
difference=$((compare -metric PSNR file1.png file2.png diff.png))
and
difference=`compare -metric PSNR file1.png file2.png diff.png`
and various others.
Assigning compare output to a variable
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Assigning compare output to a variable
The text is written to stderr, not stdout. Put
before the close backtick.
Code: Select all
2>&1
snibgo's IM pages: im.snibgo.com
Re: Assigning compare output to a variable
Many thanks. That has solved the problem, and fortunately before I pulled all my hair out.