Linux Lab#LI04-2: Bash scripts as terminal tool

Lab

linux
lab
bash
lab
Author

albertprofe

Published

Tuesday, June 1, 2021

Modified

Friday, November 1, 2024

📘 Linux Lab#LI04-2: Bash scripts as terminal tool

To create a terminal app using bash scripts, you will need to (from Lab#LI04-1):

  1. Package the scripts into a single executable file that can be easily run from the terminal. This may involve creating a wrapper script that calls the other scripts in the correct order.

1 Solving discussion

To create a terminal app for Linux, you can use a bash script. Here are the steps to create the app with the three basic (help, update, show) options:

  1. Create a bash script file with the name qtool (without any extension).

  2. Add the following lines at the beginning of the script to make it executable:

#!/bin/bash
  1. Add the following lines to create the “help” option:
if [ "$1" == "help" ]
then
    echo "qmdtool is a tool for managing Quarto markdown files (qmd)."
    echo "Available options:"
    echo "  help    Display this help message"
    echo "  update  Update the qmd files in the current directory"
    echo "  show    Display the content of the qmd files in the current directory"
    exit 0
fi
  1. Add the following lines to create the “update” option:
if [ "$1" == "update" ]
then
    echo "Updating qmd files in the current directory..."
    # Add code here to update the qmd files
    exit 0
fi
  1. Add the following lines to create the “show” option:
if [ "$1" == "show" ]
then
    echo "Displaying content of qmd files in the current directory..."
    # Add code here to display the content of the qmd files
    exit 0
fi
  1. Save the script and make it executable with the following command:
chmod +x qtool
  1. Now you can use the app by running the following command:
./qtool [option]

Replace [option] with one of the available options: “help”, “update”, or “show”. For example, to display the help message, you can run the following command:

./qtool help
Back to top