[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#679042: Bug#674022: dpkg: error: --compare-versions takes three arguments: <version> <relation> <version>



On Tue, 26 Jun 2012, Norbert Preining wrote:
> On Mo, 25 Jun 2012, Anders Kaseorg wrote:
> > I still think the logic here is not what was intended.  Because of the 
> > underquoting, [ -n $old_version ] _always_ returns true, so that the 
> 
> No, it returns true only if an old version is set, that is on upgrades.

That’s the same mistake I made when reading that the first time, before 
you pointed out that [ -n ] returns true.  As you can see, the 
underquoting really does cause [ -n $old_version ] to always return true:
  $ old_version=
  $ if [ -n $old_version ]; then echo true; else echo false; fi
  true
  $ old_version=12345
  $ if [ -n $old_version ]; then echo true; else echo false; fi
  true
(This is because [ -n ] is interpreted as the [ STRING ] form of test, not 
the [ -n STRING ] form of test.)

Quoting "$old_version" correctly would have fixed this, revealing the 
other bug.
  $ old_version=
  $ if [ -n "$old_version" ]; then echo true; else echo false; fi
  false
  $ old_version=12345
  $ if [ -n "$old_version" ]; then echo true; else echo false; fi
  true

Anders



Reply to: