Interactive file and explorer
Rakesh Kumar
Test engineer|Deployment|HSS| HLR| IMS| 5G| SIP| SDP|HTTP2|PFCP|Diameter protocol|IMS Deployment| Docker &Kubernetes|
description:- we will create a bash script that serves as an interactive file and directory explorer. The script will allow us to explore the files and directories in the current path and provide a character counting feature for the user's input.
The script will have two main parts:-
Part1: File and directory exploration
Part2: Character counting
领英推荐
Example:
$ ./explorer.sh
Welcome to the Interactive File and Directory Explorer!
Files and Directories in the Current Path:
- file1.txt (100 KB)
- dir1 (2 MB)
- script.sh (3 KB)
...
Enter a line of text (Press Enter without text to exit): Hello, this is a sample line.
Character Count: 27
Enter a line of text (Press Enter without text to exit): Another line to count.
Character Count: 25
Enter a line of text (Press Enter without text to exit):
Exiting the Interactive Explorer. Goodbye!
Submission Instructions:
Code:
#!/bin/bash
# First line of the script is the shebang which tells the system how to execute
# Part 1: File and Directory Exploration
echo "Welcome to the Interactive File and Directory Explorer "
while true; do
# List all files and directories in the current path
echo "Files and Directories in the Current Path:"
ls -lh
# Part 2: Character Counting
read -p "Enter a line of text (Press Enter without text to exit): " input
# Exit if the user enters an empty string
if [ -z "$input" ]; then
echo "Exiting the Interactive Explorer. Goodbye!"
break
fi
# Calculate and print the character count for the input line
char_count=$(echo -n "$input" | wc -m)
echo "Character Count: $char_count"
done