Search code examples
shellconfigure

What does a colon do in this GNU configure script?


I'm looking at the differences between configure scripts for two versions of Apache and I have noticed the following in the new version of configure:

if [ some test ]; then :
    do this
else
    do that

versus the old version:

if [ some test ]; then
    do this
else
    do that

The only difference is that : (colon), no-op, after the then statement.

Edit 1: So the new version is basically saying:

if "this" then "do nothing"
    "do this"
else
    "do that"

What's the intent of deliberately adding that colon?

N.B. I have seen this similar question What Is the Purpose of the `:' (colon) GNU Bash Builtin? but that doesn't cover this particular scenarios.

Edit 2: This is visible when you compare the configure script for the Apache APR in release 2.2.17 against that in release 2.2.24.

Download the two tarballs from the Apache site and after untarring the configure file is located in the directory httpd-2.2.x/srclib/apr for both releases.

Line 26015 in the v2.2.24 version shows this construct.


Solution

  • The colon built-in in this case does what it always does: nothing, successfully.

    You can always write a command after the then keyword, like this:

    if [ some test ]; then do one thing
        do another thing
    fi
    

    In this particular case the author is using : as the first command, possibly because of the typographic effect.

    Another reason to use : after the then keyword could be ensuring correctness in case lines are removed or commented in the if statement. For example this would be illegal syntax if the colon was removed:

    if [ some test ]; then :
        # do one thing     ## Disabled due to bug #12992
    fi