#!/bin/bash
# Define the main menu function
main_menu() {
clear
echo "Navigation Menu"
echo "----------------"
echo "1. List files and directories"
echo "2. Change directory"
echo "3. Quit"
echo
read -p "Enter your choice: " choice
case $choice in
1)
list_files_and_directories
;;
2)
change_directory
;;
3)
exit 0
;;
*)
echo "Invalid choice. Please try again."
;;
esac
}
# Function to list files and directories in the current directory
list_files_and_directories() {
clear
echo "List of files and directories in $(pwd):"
echo "---------------------------------------"
ls -l
echo
read -p "Press Enter to continue..."
main_menu
}
# Function to change the current directory
change_directory() {
clear
read -p "Enter the directory path: " new_dir
if [ -d "$new_dir" ]; then
cd "$new_dir"
echo "You are now in: $(pwd)"
read -p "Press Enter to continue..."
else
echo "Directory does not exist."
read -p "Press Enter to continue..."
fi
main_menu
}
# Main script execution starts here
main_menu
Linux Bash Script • 2 min read
Description
Linux Bash Script that helps with navigating file systems