jeudi 23 avril 2020

Bash If Else statement inside one line command

I've got a case:

case $1 in
  "start") exec docker-compose up ;;
  "check-types") docker-compose run --rm myapp mypy --config-file=mypy.ini $2;;
  "help" | *) print-help ;;
esac

I would like to replace $2 written in "check-types" with an if statment which would state something similar to:

if [[ $2 ]]; then
  $2
else
  .
fi

Is that possible in one line of bash?

Example of the desired behavior:

  • writing ./cli check-types executes docker-compose run --rm myapp mypy --config-file=mypy.ini .
  • writing ./cli check-types app/test executes docker-compose run --rm myapp mypy --config-file=mypy.ini app/test

Aucun commentaire:

Enregistrer un commentaire