Skip to content

fix(redirect): >> append to file duplicates content in compound commands #1119

@chaliy

Description

@chaliy

Summary

When a compound command block uses >> (append) to build a file incrementally, content gets duplicated. This manifests as duplicate footer sections in generated HTML files.

Reproduction

echo "line1" > /tmp/test.html
echo "line2" >> /tmp/test.html
# So far, so good

# But in bashblog's create_includes pattern:
if [[ -f footer_file ]]; then
    cp footer_file .footer.html
else
    {
        echo "<div>footer line 1</div>"
        echo "<div>footer line 2</div>"
    } >> ".footer.html"   # This appends when .footer.html already exists
fi

The result is .footer.html containing the footer content twice.

Context

Discovered while running bashblog via bashkit CLI. The create_includes() function first creates .header.html with >, then appends .footer.html with >>. After a rebuild cycle, the generated HTML files contain duplicate <div id="footer"> sections.

Observed in rebuilt post files:

<div id="footer">CC by-nc-nd ... bashblog</div>
<div id="footer">CC by-nc-nd ... bashblog</div>  <!-- duplicate -->

Expected behavior

>> should append to the file exactly once per write operation. The file should not accumulate duplicate content across rebuild cycles when the same script creates and then appends to the same file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions