Bash Script Example of a Console Menu

Tiempo de lectura: < 1 minuto

EnlighterJSRAW”>#!/bin/bash
Function to print “Hello”
function hello() {
echo “Hello”
}
Function to print “Goodbye”
function goodbye() {
echo “Goodbye”
}
Menu
echo “Select an option:”
echo “1. Print Hello”
echo “2. Print Goodbye”
echo “3. Print Hello and Goodbye”
read option
case $option in
1)
hello
;;
2)
goodbye
;;
3)
hello
goodbye
;;
*)
echo “Invalid option”
;;
esac

Here’s a script that generates a menu based on the selected option:

Sure! Here’s an example of how to do it:

bash

Leave a Comment