Linux Lab#LI04-2: Bash scripts as terminal tool
Lab
linux
lab
bash
lab
📘 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):
- 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:
Create a bash script file with the name
qtool
(without any extension).Add the following lines at the beginning of the script to make it executable:
- 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
- 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
- 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
- Save the script and make it executable with the following command:
- Now you can use the app by running the following command:
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: