0

Writing a bash script which might receive an optional parameter and run.

The code looks like:

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

If the parameter is specified the path should be integration_tests.tests.path.to.module. If not integration_tests.tests

Notice the dot after tests.

Question

How to modify integration_tests.tests$@ to handle this properly? Smth like integration_tests.tests${@:-.@}

1 Answer 1

3

You want ${1:+.}. The + means that if the variable is set, use this text, otherwise nothing.

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

Update: Missed quotes in case $1 has spaces or such.

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.