代码之家  ›  专栏  ›  技术社区  ›  0leg

Bash条件输入

  •  0
  • 0leg  · 技术社区  · 7 年前

    可能会收到 一 可选参数 然后跑。

    代码如下所示:

    docker-compose exec foo ./manage.py test integration_tests.tests$@ --noinput

    如果指定了参数,则路径应为 integration_tests.tests.path.to.module .如果不是 integration_tests.tests

    注意后面的点 tests .

    问题

    如何修改 integration_tests.tests$@ 要妥善处理这件事?Smth-like integration_tests.tests${@:-.@}

    1 回复  |  直到 7 年前
        1
  •  3
  •   Tanktalus    7 年前

    你想要 ${1:+.} 这个 + 这意味着,如果设置了变量,请使用此文本,否则不使用任何内容。

    docker-compose exec foo ./manage.py test "integration_tests.tests${1:+.}$1" --noinput
    

    使现代化 :错失报价以防万一 $1 有空格之类的。

    推荐文章