Skip to content

<< inside ${…} within a multi-line $(…) is read as a here-document opener, so the substitution never closes #18

Closed

Description

@steventhomasnz

unbash version: 6.0.1

Reproduction

import { parse } from "unbash";

parse("x=$(echo ${x#<<}\n)\necho after");
// errors: ["unterminated command substitution"]
// statements: one (the assignment); `echo after` is swallowed into the substitution

The same text parses cleanly when any one of these changes:

Input Errors Top-level statements
x=$(echo ${x#<<}\n)\necho after unterminated command substitution 1
x=$(echo ${x#<<}) (one line) none 1
x=$(echo ${x#a})\necho after none 2
x=$(echo "${x#<<}"\n)\necho after (quoted) none 2
echo ${x#<<} (top level) none 1

Expected: the same as bash. GNU bash 5.2.21 reads << here as the pattern of a # removal, not a here-document operator. It closes the substitution at ) and runs echo after. We checked by running the input under bash with stub commands.

It looks as if the multi-line command-substitution scan treats the << inside the unquoted ${…} as a here-document opener, and then looks for a delimiter line that never comes.

Thanks for unbash: it reads real CI steps closer to bash than anything else we measured.

Activity

  1. webpro commented on Oct 30, 2026

    @webpro
    Member

    🚀 This issue has been resolved in v6.0.2. See Release 6.0.2 for release notes.

  2. webpro commented on Oct 30, 2026

    @webpro
    Member

    Thanks for the report and reproduction. Should be fixed now.

    Very glad to hear you appreciate unbash!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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