Sorry for the title, I really can't explain better. I'm learning shell programming.
I'm trying to detect if Composer has a script named "post-install-cmd". To do that, one can call composer run-script --list
(documentation). So i pipe that command to grep -q
inside a conditional.
When I run this inside a Docker layer (distribution is Debian-based), i only get an error when calling composer run-script --list
inside the conditional:
RUN set -eux; \
if [ -f composer.json ]; then \
composer dump-autoload --no-dev --classmap-authoritative; \
# This is working fine, a list is returned (see log)
composer run-script --list; \
# This gives me an error (Unable to write output)
if composer run-script --list | grep -q post-install-cmd; then \
echo "Script was found!"; \
fi; \
fi
Log:
#41 [myproject php_prod 9/10] RUN set -eux; if [ -f composer.json ]; then composer dump-autoload --no-dev --classmap-authoritative; composer run-script --list; if composer run-script --list | grep -q post-install-cmd; then echo "Script was found!"; fi; fi
#41 0.441 + [ -f composer.json ]
#41 0.445 + composer dump-autoload --no-dev --classmap-authoritative
#41 0.835 Generating optimized autoload files (authoritative)
#41 0.878 Generated optimized autoload files (authoritative) containing 40 classes
#41 0.892 + composer run-script --list
#41 1.164 scripts:
#41 1.168 auto-scripts Runs the auto-scripts script as defined in composer.json.
#41 1.169 post-install-cmd
#41 1.169 post-update-cmd
#41 1.183 + grep -q post-install-cmd
#41 1.188 + composer run-script --list
#41 1.468 scripts:
#41 1.471
#41 1.479
#41 1.480 [Symfony\Component\Console\Exception\RuntimeException]
#41 1.481 Unable to write output.
#41 1.481
#41 1.481
#41 1.482 run-script [--timeout TIMEOUT] [--dev] [--no-dev] [-l|--list] [--] [<script>] [<args>]...
#41 1.482
#41 1.495 + echo Script was found!
#41 1.497 Script was found!
#41 DONE 1.6s