I have written a script to find all running docker containers with a certain name and it works when I directly type it into my terminal but as soon as I put it a Makefile it throws an error
/bin/sh: 1: Bad substitution
This is the script in makefile:
remote: FORCE
   docker ps -q --filter name=$$(tmp=$${PWD##*/} && printf "%s_workspace" "$${tmp//./}")
To clarify what that chunk after name= is doing, it's trying to get the current folder name and remove all .'s and append it to my container name which is workspace.
The substitution operator you are using isn't supported by /bin/sh. You need to tell make to use bash instead:
SHELL := /bin/bash
If you want to keep your recipe POSIX-compatible, use tr instead:
remote: FORCE
        docker ps -q --filter name=$$(printf '%s_workspace' "$${PWD##*/}" | tr -d .)
If you are using GNU make, you might want to use
remote: FORCE
        docker ps -q --filter name=$(subst .,,$(notdir $(PWD)))_workspace
instead to let make to all the string processing itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With