(solved) Script Problem

General support questions
Post Reply
mechanicus
Posts: 15
Joined: 2012/07/26 15:02:29

(solved) Script Problem

Post by mechanicus » 2018/03/21 21:49:46

I've wrote a script for deleting blank scannes pageges.
In my former Fedora 24 it runs well in the bash:

Code: Select all

$ ~/Desktop/testscript
7345429 1,0M -rw-rw-r--. 1 tim tim 1021K 21. Mär 21:32 out001.pnm
7345430 1,0M -rw-rw-r--. 1 tim tim 1021K 21. Mär 22:09 out002.pnm
out002.pnm seems to be blank - removing it...
Thats's right, there are two scanned pages and out002.pnm is blank.

Now in CentOS 7 the script fails with the following errors:

Code: Select all

$ ~/Desktop/testscript
(standard_in) 1: syntax error
1577485 1,0M -rw-rw-r--. 1 tim tim 1021K 21. Mär 21:30 out001.pnm
/home/tim/Desktop/testscript: Zeile 8: [: : Ganzzahliger Ausdruck erwartet.
(standard_in) 1: syntax error
1577486 1,0M -rw-rw-r--. 1 tim tim 1021K 21. Mär 21:30 out002.pnm
/home/tim/Desktop/testscript: Zeile 8: [: : Ganzzahliger Ausdruck erwartet.
(Ganzzahliger Ausdruck erwartet : integer expression expected)

My script:

Code: Select all

#!/bin/bash
for i in out*.pnm
do histogram=`convert "${i}" -threshold 50% -format %c histogram:info:-`
   white=`echo "${histogram}" | grep "white" | sed -n 's/^ *\(.*\):.*$/\1/p'`
   black=`echo "${histogram}" | grep "black" | sed -n 's/^ *\(.*\):.*$/\1/p'`
   blank=`echo "scale=4; ${black}/${white} < 0.005" | bc`
echo `ls -lisah $i`
if [ "${blank}" -eq "1" ]; then
echo "${i} seems to be blank - removing it..."
rm "${i}"
fi
done
The bash versions are:
Fedora 24:

Code: Select all

Version     : 4.3.42
Release     : 7.fc24
Größe       : 6.1 M
CentOS 7:

Code: Select all

Version    : 4.2.46
Ausgabe    : 29.el7_4
Größe      : 3.5 M
Where is the mistake?
Last edited by mechanicus on 2018/03/21 22:46:20, edited 1 time in total.

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Script Problem

Post by TrevorH » 2018/03/21 22:26:09

Line 8 is if [ "${blank}" -eq "1" ]; then so your ${blank} is not set. That's meant to be set in your for i;do loop so I don't think this is a problem with bash at all, I think the output you're getting from the convert command is different to what you're expecting.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mechanicus
Posts: 15
Joined: 2012/07/26 15:02:29

Re: Script Problem

Post by mechanicus » 2018/03/21 22:43:14

Thank you, that's really the difference!
in F24:

Code: Select all

$ convert out001.pnm -threshold 50% -format %c histogram:info:-
    595395: (  0,  0,  0) #000000 black
   7762493: (255,255,255) #FFFFFF white
In CentOS 7:

Code: Select all

$ convert out001.pnm -threshold 50% -format %c histogram:info:-
    595395: (  0,  0,  0) #000000 gray(0,0,0)
   7762493: (255,255,255) #FFFFFF gray(255,255,255)
Gray instead of black and white! :o

Post Reply