Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
How to execute two function one by one in the list of functions in the script.sh file

I want two functions called one by one in a single bash command.

  1. I tried by calling in bash
  2. ./script run delete_code run stop_node_pool - But it executes first function and stops. second function was not started.
  3. ./script delete_code - If we give one function name its work for a particular function. But I need to call two functions that I choose while executing the script in bash.
  4. How to write a program for executing any two functions one by one in a list of functions available in the script.sh file.

My sample code

#!/bin/bash
   
    
    delete_code() { 
    echo "code deleted"
    $1 && shift && "@a"
    }
    
    create_code() { 
    echo "code created"
    $1 && shift && "@a"
            }
    
    stop_node_pool() { 
    echo "node pool stopped"
    $1 && shift && "@a"
    }
    
    start_node_pool() { 
    echo "node pool start"
    $1 && shift && "@a"
    }

EXECUTION 
case $1 in
    delete_code) "$@"; exit;;
    create_code) "$@"; exit;;
    stop_node_pool) "$@"; exit;;
    start_node_pool) "$@"; exit;;

esac

delete_code
create_code
stop_node_pool
start_node_pool
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I'm not sure I understand your problem (your question is confusing) but perhaps this will solve your issue:

#!/bin/bash

usage() { echo "Usage: $0 <code_deleted|code_created|node_pool_stopped|node_pool_start>" 1>&2; exit 1; }

# unless there are 2 arguments, print the "usage" and exit
[ ! $# -eq 2 ] && usage

# Functions
delete_code() {
    echo "code deleted test"
}

create_code() {
    echo "code created test"
}

stop_node_pool() {
    echo "node pool stopped test"
}

start_node_pool() {
    echo "node pool start test"
}

# Execution
for i in "$@"
do

    case "$i" in

        code_deleted)
            delete_code &
            ;;

        code_created)
            create_code &
            ;;

        node_pool_stopped)
            stop_node_pool &
            ;;

        node_pool_start)
            start_node_pool &
            ;;

        *)
            usage
            ;;
    esac
done
wait
over 4 years ago · Santiago Trujillo Relatório

0

#!/bin/bash

usage() { echo "Usage: $0 <code_deleted|code_created|node_pool_stopped|node_pool_start>" 1>&2; exit 1; }

# unless there are 2 arguments, print the "usage" and exit
[ ! $# -eq 2 ] && usage

# Functions
delete_code() {
    echo "code deleted test"
}

create_code() {
    echo "code created test"
}

stop_node_pool() {
    echo "node pool stopped test"
}

start_node_pool() {
    echo "node pool start test"
}

# Execution
for i in "$@"
do

    case "$i" in

        code_deleted)
            delete_code &
            ;;

        code_created)
            create_code &
            ;;

        node_pool_stopped)
            stop_node_pool &
            ;;

        node_pool_start)
            start_node_pool &
            ;;

        *)
            usage
            ;;
    esac
wait
done
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda