0

I have this example:

migrate(){
    case $1 in 
        "team_container")
            echo "Rodando Migrate de ${1}",

            ;;
        "evaluation_container")
            echo "Rodando Migrate de ${1}",

            ;;
        "school_container")
            echo "Rodando Migrate de ${1}",

            ;;
        "class_container")
            echo "Rodando Migrate de ${1}",

            ;;
        "student_container")
            echo "Rodando Migrate de ${1}",

            ;;
        "messages_container")
            echo "Rodando Migrate de ${1}",

            ;;
        "logs_container")
            echo "Rodando Migrate de ${1}",

            ;;
    esac
}
export MIGRATE=migrate;
docker ps  --format {{.Names}} | xargs bash -c "MIGRATE {}"

Output:

MIGRATE: command not found

xargs cannot find the function, even if exporting it and calling a subshell.

How can i pass my function migrate as parameter to xargs?

Lucas Marinzeck
  • 313
  • 4
  • 11

1 Answers1

1

Pass it as argument:

xargs -n1 bash -c 'migrate "$1"' _

Remember to export your function:

export -f migrate
KamilCuk
  • 120,984
  • 8
  • 59
  • 111