Bug #35723 Incorrect syntax in mysql_install_db script under Solaris
Submitted: 31 Mar 2008 22:13 Modified: 3 Apr 2008 8:24
Reporter: Peter Schultze Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S2 (Serious)
Version:5.0.51a OS:Solaris
Assigned to: Hartmut Holzgraefe CPU Architecture:Any

[31 Mar 2008 22:13] Peter Schultze
Description:
The   mysql_install_db script contains lines like 

if test ! -f "$f"
if test ! -x "$mysqld"
if test ! -d $dir

This is incorrect syntax under Solaris /bin/sh,
which prevents the script from being executed correctly in the postinstall
phase of pkgadd

How to repeat:
execute mysql_install_db under Solaris

Suggested fix:
Replace  with the following syntax

if [ ! -f "$f" ]
if [ ! -x "$mysqld" ]
if [ ! -d $dir ]

This does work under Linux as well as under Solaris.
[1 Apr 2008 14:34] Hartmut Holzgraefe
"test" and "[" are actually only different synonyms for the same functionality
and both accept the same primitives, including the ! operator.

The only difference between the invocation as "test" and as "[" is that "[" requires a closing "]" as its last parameter.

So the following two snippets work the same, even in Solaris /bin/sh 
(at least back to Solaris 8):

  if test ! -f foo
  then
    echo yes
  else
    echo no
  fi

  if [ ! -f foo ]
  then
    echo yes
  else
    echo no
  fi

You can also check the Solaris man page on test to verify that both should work the same.

The "test" variant is even recommended over the "[" for when writing autoconf macros for portability reasons, see e.g.:

  http://sources.redhat.com/autobook/autobook/autobook_216.html#SEC216

What is indeed considered non-portable is the use of "if ! test" instead of "if test !" but we are not doing that anyway.

So whatever is breaking pkgadd here must be something else ... can you provide the exact error messages you are getting from it?
[1 Apr 2008 15:32] Hartmut Holzgraefe
Thank you for taking the time to report a problem.  Unfortunately you are not using a current version of the product you reported a problem with -- the problem might already be fixed. Please download a new version from http://www.mysql.com/downloads/

If you are able to reproduce the bug with one of the latest versions, please change the version on this bug report to the version you tested and change the status back to "Open".  Again, thank you for your continued support of MySQL.

The 5.0.51 version of mysql_install_db does indeed use "if ! test" instead of "if test !", this has been fixed staring with mysql 5.0.54 though. As i was looking at current sources when writing my original reply i did not see the nonportable use of "if ! test" then
[3 Apr 2008 8:24] Hartmut Holzgraefe
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html
[24 Apr 2008 4:36] Valeriy Kravchuk
Bug #36307 was marked a duplicate of this one.
[13 Jul 2008 14:40] Sveta Smirnova
Bug #38082 was marked as duplicate of this one.