我正在使用tox内的目录环境变量将arg传递给shell脚本,该脚本等待数据库迁移完成再开始测试。如果运行此命令,尽管在$1
脚本中回显.sh
时参数丢失了。
[tox]
envlist = py27
skipsdist=True
[testenv]
passenv = *
deps = -r {env:APP_ROOT}/requirements.txt
commands_pre = {env:APP_ROOT}/scripts/wait-for-db.sh {env:DBSENTINEL}/.db-migrations-ready
usedevelop = true
commands = py.test
commands_post = /bin/rm {env:DBSENTINEL}/.db-migrations-ready
我最终得到
Darwin run-test-pre: commands[0] | /Users/alexander/projects/python-services/scripts/wait-for-db.sh /Users/alexander/projects/python-services/.db-migrations-ready
.db-migrations-ready
除了在shell脚本中回显之外,我要做的是在run-test-pre
输出/Users/alexander/projects/python-services/.db-migrations-ready
中看到的完整路径。相反,只有.db-migrations-ready
通过。
如果我将pre_commands
更改为
commands_pre = {env:APP_ROOT}/scripts/wait-for-db.sh {env:DBSENTINEL}//.db-migrations-ready
然后我看到了完全替代的回声
Darwin run-test-pre: commands[0] | /Users/alexander/projects/python-services/scripts/wait-for-db.sh /Users/alexander/projects/python-services//.db-migrations-ready
/Users/alexander/projects/python-services//.db-migrations-ready
我猜想这与转义,格式化或argparse问题有关,但不确定。我需要做的是{env:DBSENTINEL}解压缩设置的目录路径,并以$arg1
的形式传递到Shell脚本。
答案 0 :(得分:0)
单引号似乎可以解决,我认为这与this Github问题有关。
commands_pre = {env:APP_ROOT}/scripts/wait-for-db.sh '{env:DBSENTINEL}/.db-migrations-ready'
Darwin run-test-pre: commands[1] | /Users/alexander/projects/python-services/scripts/wait-for-db.sh /Users/alexander/projects/python-services/.db-migrations-ready
/Users/alexander/projects/cloud/python-services/.db-migrations-ready