def bamListCatCmd(samtoolsBin, bamList, output) :
    """
    Concatenate an input list of bam files to an output bam file, and index.

    If len(bamList) is 1 the file will be moved to the output file name.
    """
    assert(len(bamList) > 0)

    if len(bamList) > 1:
        headerTmp = bamList[0] + "header"
        cmd  = "\"%s\" view -H \"%s\" >| \"%s\"" % (samtoolsBin, bamList[0], headerTmp)
        cmd += " && \"%s\" merge -h \"%s\" \"%s\" " % (samtoolsBin, headerTmp, output)
        cmd += " ".join(bamList)
    else:
        cmd = "mv -f \"%s\" \"%s\"" % (bamList[0], output)
    return cmd + " && \"%s\" index \"%s\"" % (samtoolsBin, output)