Answer the question
In order to leave comments, you need to log in
How to decrypt given .sh file?
I am not familiar with bash, but I ran into a problem, and I want to delve a little. There is a file that automatically creates a docker container and destroys it after a timeout. I would be grateful if you explain the logic of this script, especially grateful if you describe line by line what it does. (immediately incomprehensible and introduces into a stupor, set -e
to=$1
etc.)
#!/bin/bash
set -e
to=$1
shift
cont=$(docker run --rm -d "[email protected]")
code=$(timeout "$to" docker wait "$cont" || true)
docker kill $cont &> /dev/null
echo -n 'status: '
if [ -z "$code" ]; then
echo timeout
else
echo exited: $code
fi
echo output:
# pipe to sed simply for pretty nice indentation
docker logs $cont | sed 's/^/\t/'
docker rm $cont &> /dev/null
Answer the question
In order to leave comments, you need to log in
set -e sets the exit mode on the first error.
to=$1 - the variable to is assigned the first argument with which the script was called, for example setup.sh local, $1 will contain "local"
and there are also commands such as man
man set
man shift
man docker
man man
=)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question