Skip to content

declare -f doesn't work properly with some function defs #111

@SleepyMug

Description

@SleepyMug

declare -f does not produce a function that is syntactically correct if it has a particular usage of heredoc and &&.
Example:

a() {
    echo hi &&
    cat >/dev/null <<-EOF &&
    texttexttext
EOF
    echo bye
}

with declare -f the definition will become

a () 
{ 
    echo hi && cat > /dev/null <<-EOF
    texttexttext
EOF
 && echo bye
}

which will trigger a syntax error if parsed as shell script (notice the change of position of &&).

It seems that the first command and the third command are necessary for this behavior.

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