Quote command substitution which may have spaces

If $(pwd) or $(uname -s) contain spaces, their output will undergo word
splitting and be passed as multiple arguments, which would cause the
programs receiving them to misbehave.  Avoid this by quoting.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
Kevin Locke 2020-06-07 07:33:40 -06:00 committed by pbokoc
parent 9c1c2c7394
commit 7ed450f0c4
2 changed files with 7 additions and 7 deletions

View file

@ -10,9 +10,9 @@ if [ "$(uname)" = "Darwin" ]; then
echo "" echo ""
echo "This build script is using Docker container runtime to run the build in an isolated environment." echo "This build script is using Docker container runtime to run the build in an isolated environment."
echo "" echo ""
docker run --rm -it -v $(pwd):/antora $image $cmd docker run --rm -it -v "$(pwd):/antora" $image $cmd
elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then elif [ "$(expr substr "$(uname -s)" 1 5)" = "Linux" ]; then
# Running on Linux. # Running on Linux.
# Check whether podman is available, else faill back to docker # Check whether podman is available, else faill back to docker
# which requires root. # which requires root.
@ -21,7 +21,7 @@ elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then
echo "" echo ""
echo "This build script is using Podman to run the build in an isolated environment." echo "This build script is using Podman to run the build in an isolated environment."
echo "" echo ""
podman run --rm -it -v $(pwd):/antora:z $image $cmd podman run --rm -it -v "$(pwd):/antora:z" $image $cmd
elif [ -f /usr/bin/docker ]; then elif [ -f /usr/bin/docker ]; then
echo "" echo ""
@ -29,13 +29,13 @@ elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then
echo "" echo ""
if groups | grep -wq "docker"; then if groups | grep -wq "docker"; then
docker run --rm -it -v $(pwd):/antora:z $image $cmd docker run --rm -it -v "$(pwd):/antora:z" $image $cmd
else else
echo "" echo ""
echo "This build script is using $runtime to run the build in an isolated environment. You might be asked for your password." echo "This build script is using $runtime to run the build in an isolated environment. You might be asked for your password."
echo "You can avoid this by adding your user to the 'docker' group, but be aware of the security implications. See https://docs.docker.com/install/linux/linux-postinstall/." echo "You can avoid this by adding your user to the 'docker' group, but be aware of the security implications. See https://docs.docker.com/install/linux/linux-postinstall/."
echo "" echo ""
sudo docker run --rm -it -v $(pwd):/antora:z $image $cmd sudo docker run --rm -it -v "$(pwd):/antora:z" $image $cmd
fi fi
else else
echo "" echo ""

View file

@ -5,9 +5,9 @@ if [ "$(uname)" = "Darwin" ]; then
# Let's assume that the user has the Docker CE installed # Let's assume that the user has the Docker CE installed
# which doesn't require a root password. # which doesn't require a root password.
echo "The preview will be available at http://localhost:8080/" echo "The preview will be available at http://localhost:8080/"
docker run --rm -v $(pwd):/antora:ro -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro -p 8080:80 nginx docker run --rm -v "$(pwd):/antora:ro" -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro" -p 8080:80 nginx
elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then elif [ "$(expr substr "$(uname -s)" 1 5)" = "Linux" ]; then
# Running on Linux. # Running on Linux.
# Fedora Workstation has python3 installed as a default, so using that # Fedora Workstation has python3 installed as a default, so using that
echo "" echo ""