-3

I want to check if a folder exists in a docker then in a bash script act according to the answer:

toto = docker exec -it symfony sh -c " test -d imports && echo '1' "
if [[ "$toto" == '1' ]]; then
echo "il exists"
fi
Camel4488
  • 323
  • 1
  • 3
  • 9
  • (This seems like a slightly odd workflow to me; I'd normally expect the container's filesystem layout to be basically fixed in the `Dockerfile`, and for that to be totally hidden from the host. When would the container only maybe have the directory? How would the host behave differently?) – David Maze Jan 10 '23 at 13:59
  • it's for a bash script that actually updates postgres – Camel4488 Jan 10 '23 at 15:33

1 Answers1

1

Just run the command inside docker container.

if docker exec symfony test -d imports; then
    echo "il exists"
fi
if docker exec symfony [ -d imports ]; then
    echo "il exists"
fi

Your code has many problems. Check your script with shellcheck. Consider reading: How do I set a variable to the output of a command in Bash?

KamilCuk
  • 120,984
  • 8
  • 59
  • 111