My script:
#! /bin/bash --
set -x
## docker-compose wrapper
compose_fn() {
local ENV="${1}"
local VERB="${2}"
local SERVICE="${3}"
local CMD="docker-compose -f ${ENV}.yml"
case "${VERB}" in
(exec)
shift "$#" # remove args passed to this fn
# Execute a command in a running container.
if [ -n "${SERVICE}" ]; then
${CMD} "${VERB}" "${SERVICE}" "$@"
else
echo "## Err: You must specify service name..."
exit 1
fi
;;
esac
}
compose_fn "${1}" "${2}" "${3}"
Is giving me a hard time with the following error:
$ ./tst.sh dev exec django sh
+ compose_fn dev exec django
+ local ENV=dev
+ local VERB=exec
+ local SERVICE=django
+ local 'CMD=docker-compose -f dev.yml'
+ case "${VERB}" in
+ shift 3
+ '[' -n django ']'
+ docker-compose -f dev.yml exec django
Execute a command in a running container
Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]
Options:
....
Where is my mistake? How can it be done better?
As far as I can tell I've passed 4 args [dev, exec, django, sh]
to the script, then within the script removed 3 (shift 3
), therefore sh
should have been left in the $@
var.