Skip to content

Escape {0}, {1}, {N}... in commands and files strings #763

Discussion options

You must be logged in to vote

As an aside, I've worked around this for now with a little shell magic:

git diff-tree -r --name-only --no-commit-id HEAD@{$(echo 1)} HEAD

Looking at the relevant code it seems like there isn't any built-in way to do this

func replacePositionalArguments(str string, args []string) string {
str = strings.ReplaceAll(str, "{0}", strings.Join(args, " "))
for i, arg := range args {
str = strings.ReplaceAll(str, fmt.Sprintf("{%d}", i+1), arg)
}
return str
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mrexox
Comment options

@craigthompsonhive
Comment options

@mrexox
Comment options

Answer selected by craigthompsonhive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants