Article 4WMZ8 error comparing strings

error comparing strings

by
pedropt
from LinuxQuestions.org on (#4WMZ8)
I am building a script to manually update my dovecot packages directly from dovecot repo , however this script does not do that job straight ahead .
First checks apt policy to see witch packages of dovecot are installed in system , and then write those packages names to a file .

I am posting here this part only of the code , but when i look into the logfile from apt and compare strings with IF statement i get "invalid arithmetic operator on my loop."

Code:#!/bin/bash
basedir="/dovecot"
if [[ ! -d "$basedir" ]]
then
mkdir "$basedir"
mkdir "$basedir/update"
else
rm -f "$basedir/update/*.*"
rm "$basedir/dovelist"
rm "$basedir/filelist"
rm "$basedir/dovelist"
fi
echo "Checking dovecot installed packages"
apt-cache policy dovecot-* > aptinst

# get the line numbers where dovecot- exists
grep -n "dovecot-" aptinst | sed 's/\:/ /' | awk '{print$1}' > lines
a1=$(wc -l lines | awk '{print$1}')
for i in $(seq "$a1")
do

# read i line from lines file"
ln=$(sed -n ${i}p lines)

# add +1 to that line number (this will get Installed line)
ln=$((ln+1))

# On installed line bings up variable 2
rdinst=$(sed -n ${ln}p aptinst | awk '{print$2}' | sed 's/^.*://')
rjct="(none)"
echo "reading line $ln with output $rdinst"

# here checks if variable 2 is not equal to (none)
# (none) means package not installed
# in case some particular package is installed then a #version number will appear on variable2

if [[ "$rdinst" -ne "$rjct" ]]
then
if [[ ! -f "$basedir/installed" ]]
then
namepkg=$(sed -n ${i}p aptinst)
echo "Installed $namepkg with version $rdinst" > installed
else
namepkg=$(sed -n ${i}p aptinst)
echo "Installed $namepkg with version $rdinst" >> installed
fi
fi
done

exit 0Eventually the problem is in the if statement , i changed the -ne with != and i did not get accurate outputlatest?d=yIl2AUoC8zA latest?i=d7iMSowSV0Y:mTA3TkBvKOc:F7zBnMy latest?i=d7iMSowSV0Y:mTA3TkBvKOc:V_sGLiP latest?d=qj6IDK7rITs latest?i=d7iMSowSV0Y:mTA3TkBvKOc:gIN9vFwd7iMSowSV0Y
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments