0% found this document useful (0 votes)
6 views4 pages

Script 5

The document outlines a shell script that allows users to perform various file and directory operations, including creating a file to store personal information, displaying its contents, deleting directories, sorting a numeric file, and changing file permissions. It provides a menu-driven interface where users can choose an option to execute the corresponding command. The script includes error handling for invalid choices.

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)
6 views4 pages

Script 5

The document outlines a shell script that allows users to perform various file and directory operations, including creating a file to store personal information, displaying its contents, deleting directories, sorting a numeric file, and changing file permissions. It provides a menu-driven interface where users can choose an option to execute the corresponding command. The script includes error handling for invalid choices.

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
You are on page 1/ 4

Script No .

Definition:
Write a shell script to execute following commands
• Create a file called text and store name, age and address in it.
• Display the contents of the file text on the screen.
• Delete the directories mydir and newdir at oneshot.
• Sort a numeric file?
• Change the permissions for the file newtext to666.
Script:
echo “1. Create a file called text and store name,age and address in it.”
echo “2. Display the contents of the file text on the screen.”
echo “3. Delete the directories mydir and newdir at one shot.”
echo “4. Sort a numeric file”
echo “5. Change the permissions for the file newtext to 666.”
echo “enter your choice”
read ch
case $ch in
1) echo “Create a file called text and store name,age and address in it.”
echo “Enter the filename”
read fn
cat > $fn ;;
2) echo “Display the contents of the file text on the screen.”
cat $fn ;;
3) echo “Delete the directories mydir and newdir at one shot.”
rmdir mydir newdir ;;
4) echo “Sort a numeric file”
sort -n filename ;;
5) echo “Change the permissions for the file newtext to 666.”
chmod 666 newtext ;;
*) echo “Invalid choice” ;;
Esac

OR

echo "1. Create file called text and store name, age and address in it."
echo "2. Display the contents of the file text on the screen."
echo "3. Delete the directories mydir and newdir at one shot."
echo "4. Sort a numeric file"
echo "5. Change the permissions for the file newtext to 666."
echo "enter your choice"
read ch
case $ch in
1) echo "Create a file called text and store name, age and address in it."
echo "Enter the filename"
read fn
echo "Enter name : "
read name
echo "Enter age : "
read age
echo "Enter address : "
read adr
echo -e "Name : $name\nAge: $age\nAddress" > "$fn";;
2) echo "Displaying the contents of the file text on the screen. "
cat abc.txt;;
3) echo "Delete the directories mydir and newdir at one shot."
rmdir mydir newdir;;
4) echo "Sort a numeric file"
sort -n filename;;
5) echo "Change the permissions for the file newtext to 666."
chmode 666 newtext;;
*) echo "INvalide choice";;
esac

OR
# Make sure u have students stored data file

echo "1) Create file"


echo "2) Display contents of file"
echo "3) Delete directories and make directories"
echo "4) sort file"
echo "5) Change permission of file next to 666"
echo "Enter your choice"
read ch

case $ch in
1) cat>1.txt;;
2) cat 1.txt;;
3) rm -r mydirnewdir;;
4) sort -n 1.txt;;
5) chmod 666 1.txt;;
*) echo "Invalid choice"
esac

You might also like