0

I want just one statement to do something like:

pip3 install $([ -n "$PYPI_MIRROR"] && echo "--index-url $PYPI_MIRROR") -r requirements.txt

It means it will append --index-url <url> arguments only if the $PYPI_MIRROR variable is set.

Then I found that

pip3 install ${PYPI_MIRROR/#/--index-url } -r requirements.txt

It works with sh and bash but zsh, zsh will always got --index-url whether $PYPI_MIRROR is set or not.

And there are some other problems with the 2nd solution, such as PYPI_MIRROR is set but empty.

Is there a way to do this more reliable?

PM Extra
  • 427
  • 4
  • 17
  • 2
    I added a zsh-compatible version to my answer to ["How to (not) pass empty quoted variables as arguments to commands"](https://stackoverflow.com/questions/20306739/how-to-not-pass-empty-quoted-variables-as-arguments-to-commands); does that do what you need? – Gordon Davisson Jan 06 '23 at 02:35

0 Answers0