0% found this document useful (0 votes)
4 views3 pages

Shell Script Menu for File Operations

The document outlines a shell script that provides a menu for file operations, including displaying words in ascending and descending order, toggling characters, and checking the file type. The script prompts the user for a choice and filename, executing the corresponding operation based on the input. There are multiple variations of the script with slight differences in implementation and error handling.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Shell Script Menu for File Operations

The document outlines a shell script that provides a menu for file operations, including displaying words in ascending and descending order, toggling characters, and checking the file type. The script prompts the user for a choice and filename, executing the corresponding operation based on the input. There are multiple variations of the script with slight differences in implementation and error handling.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Script No .

Definition:
Write a shell script to display the following menu for a particular file :
i. Display all the words of a file in ascendingorder.
ii. Display a file in descendingorder.
iii. Toggle all the characters in thefile.
iv. Display type of the file.
Script:
clear
echo M E N U
echo 1: Display all the words in ascending order
echo 2: Display all words in descending order
echo 3: Toggle all chacters of the file
echo 4: Check the type of file
echo 5: Exit
echo Enter your choice
read ch
case $ch in
1) echo Enter the name of the file
read fname
for i in $(caat $fname)
do
echo $i >> temp
done
sort -r temp
rm temp;;
2) ;;
3) echo Enter the text
read text
echo $text | tr '[a-z [A-Z]' '[A-Z] [a-z]';;
4);;
5) exit;;
*) echo invalid choice;;
esac

OR
echo "1. Display all the words of a file in ascending oreder."
echo "2. Display a file in descending order."
echo "3. Toggle all the characters in the file."
echo "4. Display type of the file."
echo "Enter your choice "
read ch
echo "Enter the filename"
read fn

case $ch in
1) sort $fn;;
2) sort -r $fn;;
3) cat $fn | tr "[a-z][A-Z]" "[A-Z][a-z]";;
4) file $fn;;
*) echo "Invalide choice"

OR
echo "1. Display all the words of a file in ascending order."
echo "2. Display a file in descending order."
echo "3. Toggle all the characters in the file."
echo "4. Enter your choice"
read ch
echo "Enter your choice"
read ch
echo "Enter the filename"
read ch
case $ch in
1) sort $fn;;
2) sort -r $fn;;
3) cat $fn | tr "[a-z][A-Z]" "[A-Z][a-z]";;
4) file $fn;;
*) echo "Invalid choice"
esac

You might also like