0

I try:

ctests() {
    curl -X POST \
        http://route.to.host/cucumber/execute-tests \
        -H 'Authorization: Basic xxxxxxxxxxxxxxxxxxxxx' \
        -H 'Content-Type: application/json' \
        -H 'cache-control: no-cache' \
        -d '{ "text": "cucumber! alltests products=$1" }'
}

And want to call this like

> ctests someproduct

But $1 wont resolve. I tried ${1}, but its the same. Is there a nice solution for this?

1 Answer 1

2

the $1 doesn't resolve because you are using single-ticks ' which prohibit variable resolution.

use double-ticks (") instead (you'll have to escape the double-quotes inside the double-quotes; or use single-quotes within the double-quotes; depending on your context)

ctests() {
    curl -X POST \
        http://route.to.host/cucumber/execute-tests \
        -H 'Authorization: Basic xxxxxxxxxxxxxxxxxxxxx' \
        -H 'Content-Type: application/json' \
        -H 'cache-control: no-cache' \
        -d "{ \"text\": \"cucumber! alltests products=$1\" }"
}

quoting bash(1):

QUOTING

[...]

Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $ [...]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.