Skip to content

Escaping / character in substitution expansions #909

@dnewhall

Description

@dnewhall

While doing a naive path canonicalization I tried replacing "//" with "/", and so I wrote the following:

function canonicalize_path {
    echo "${1//\/\//\/}"
}

When I run this in Ksh, I get:

ksh$ canonicalize_path "//home////foo"
\/home\/\/foo

But when I run it in bash, I get:

bash$  canonicalize_path "//home////foo"
/home//foo

I am extremely fine with us not being bash-compatible, but is that the expected behavior? It seems to go against the default assumptions regarding strings.

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