1

I am learning bash script and made this script :

#!/bin/bash


PS3='What is your distro: '
options=("Fedora" "Ubuntu" "Arch" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "you chose Fedora"
            ;;
        "Option 2")
            echo "you chose Ubuntu"
            ;;
        "Option 3")
            echo "you chose Arch $REPLY which is $opt"
            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

I want to execute a command if I select an option for example Fedora ==> Fedora.sh

I hope someone helps me.

1
  • Replace echo "you chose Fedora" with /path/to/Fedora.sh? Commented Apr 17, 2022 at 10:13

1 Answer 1

0

It is a simple task.

Suppose you placed your scripts inside the same folder of the main script:

#!/bin/bash

SCRIPT_PATH=$(readlink -f $(dirname $0))

PS3='What is your distro: '
options=("Fedora" "Ubuntu" "Arch" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "you chose Fedora"
            ${SCRIPT_PATH}/fedora.sh
            ;;
        "Option 2")
            echo "you chose Ubuntu"
            ${SCRIPT_PATH}/ubuntu.sh
            ;;
        "Option 3")
            echo "you chose Arch $REPLY which is $opt"
            ${SCRIPT_PATH}/arch.sh
            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

Here you can get a wonderfull BASH guide.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.