![Python의 쉘 변수에 인용된 매개변수를 사용하는 방법은 무엇입니까? [복사]](https://linux55.com/image/162046/Python%EC%9D%98%20%EC%89%98%20%EB%B3%80%EC%88%98%EC%97%90%20%EC%9D%B8%EC%9A%A9%EB%90%9C%20%EB%A7%A4%EA%B0%9C%EB%B3%80%EC%88%98%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
다음과 같이 pytest 호출을 매개변수화하려고 합니다.
export OPTIONS="tests -k 'not e2e'"
pytest ${OPTIONS}
pytest
변수의 따옴표로 인해 호출이 실패했습니다. 옵션을 통화에 직접 넣는 것이 효과적입니다.
나는 시도했다:
pytest ${OPTIONS}
ERROR: file not found: tests -k 'not e2e'
pytest $(eval echo "${OPTIONS}") # removes all quotes
ERROR: file not found: e2e
pytest $(printf %s ${OPTIONS})
pytest
호출 작업을 매개변수화 하려면 어떻게 해야 합니까 ?
고쳐 쓰다
이것답변작동하는 솔루션이 포함되어 있습니다.
eval "OPTIONS=($OPTIONS)" # (opt.) convert an existing string to an array
export OPTIONS=(tests -k 'not e2e')
pytest "${OPTIONS[@]}"
이 점을 지적해 주셔서 정말 감사합니다. 나는 몇 시간 동안 검색을 해왔습니다.
답변1
이것을 시도해 보셨나요?
export OPTIONS="tests -k \'not e2e\'"
그것은 관련이 있어야합니다eval