I am trying to write an ebuild and best_version is driving me nuts :( I am trying to write something like this: best_version blah/blah && a="foo" || a="moo" but it always returned a="foo" regardless of whether blah/blah was installed or not Then I tried this: if best_version lah/blah ; then a="foo" else a="moo" fi which had the same result. After that I hit Bugzilla and found bug #34814 in which it is clearly mentioned that the correct syntax is "if best_version blah/blah ; then". Not only that, but I also remember being told by a developer the same thing (it was for use though, not best_version). And lastly, the same syntax is used in man 5 ebuild, for "use" again. After all of this I tried using the wrong (deprecated) syntax... and it worked! So, after wasting a few hours trying to figure this out, I would like a developer to make light in this situation: What is the correct syntax? Why is the syntax not consistent?
Created attachment 85064 [details] bad.sh Script showing the correct (recommended) syntax which, unfortunately, doesn't work
Created attachment 85065 [details] good.sh Script showing the old (deprecated) syntax which works
tvan@mars ~ $ portageq --help ... has_version <root> <category/package> Return code 0 if it's available, 1 otherwise. ... best_version <root> <category/package> Returns category/package-version (without .ebuild). ... tvan@mars ~ $ portageq best_version / 'sys-apps/portage' sys-apps/portage-2.1_pre7-r5 tvan@mars ~ $ echo $? 0 tvan@mars ~ $ portageq best_version / 'sys-apps/foo' tvan@mars ~ $ echo $? 0 tvan@mars ~ $ portageq has_version / 'sys-apps/portage' tvan@mars ~ $ echo $? 0 tvan@mars ~ $ portageq has_version / 'sys-apps/foo' tvan@mars ~ $ echo $? 1 for what you want to do, has_version is the one to use. tvan@mars ~ $ if portageq has_version / 'sys-apps/portage'; then echo "yes" ;else echo "no"; fi yes tvan@mars ~ $ if portageq has_version / 'sys-apps/foo'; then echo "yes"; else echo "no"; fi no
> for what you want to do, has_version is the one to use. I didn't realize that you could use has_version with just the package name, without any version number. man 5 ebuild would make you think that a version is required > tvan@mars ~ $ portageq best_version / 'sys-apps/portage' > sys-apps/portage-2.1_pre7-r5 > tvan@mars ~ $ echo $? > 0 > tvan@mars ~ $ portageq best_version / 'sys-apps/foo' > > tvan@mars ~ $ echo $? > 0 There must be something wrong somewhere since man 5 ebuild says: "The function returns 0 if there is a package that matches package name. Otherwise, the function will return 1." Please nothe the last sentence... When does best_version return 1 since in your example it always returns 0 regardless of whether the package is installed or not? Maybe I'm missing something here. Thnak you.
the behaviour demonstrated in comment 3 is correct, this is a documentation bug. or rather, it was one in revisions < 3310 *g*
This has been released in 2.1_rc1.