Script 5
Script 5
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
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