Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!