Using chmod command these shell script program has been written. Using echo it will display the message. Read keyword get the input from the user for setting the read write permission for user group and the others.
Linux shell Programming Source code
#Shell script to change the Attributes of a file using chmod commands
tput clear
n=1
while [ $n -ne 0 ]
do
echo "Menu"
echo "1. To change the permission normally"
echo "2. To change the permission using octal notation"
echo " Enter the choice"
read a
case "$a" in
1 ) echo "Enter the name of the file"
read f1
echo "Enter 1 to set the permission"
echo "Enter 2 to remove the permission"
read c
echo "Enter the group of user we want to change permission"
echo "u-users"
echo "g-group"
echo "o-others"
echo "a-all"
read f2
echo "Enter the permission we want to set"
echo "r-read"
echo "w-write"
echo "x-execute"
read f3
if test $c -eq 1
then
chmod $f2+$f3 $f1
elif test $c -eq 2
then
chmod $f2-$f3 $f1
else
echo "invalid option"
fi
echo "The permission are as follows"
ls -l $f1 ;;
2 ) echo "Enter the name of the file"
read f1
echo "Menu"
echo "0. to remove all permission"
echo "1. to set execute permission"
echo "2. to set write permission"
echo "3. to set write and execute permission"
echo "4. to set read permission"
echo "5. to set read and execute permission"
echo "6. to set read and write permission"
echo "7. to set all permissions"
ls -l $f1
echo "Enter the permission we want to change for each group of users"
echo "User"
read uu
echo "Group"
read gg
echo "Others"
read oo
chmod $uu$gg$oo $f1
echo "The permission for $f1 are as follows"
ls -l $f1 ;;
*) echo "invalid choice" ;;
esac
echo "Do u want to continue(1 YES / 0 NO )"
read n
done
Bash Shell Script Output Menu
1. To change the permission normally
2. To change the permission using octal notation
Enter the choice
1
Enter the name of the file
file2
Enter 1 to set the permission
Enter 2 to remove the permission
1
Enter the group of user we want to change permission
u-users
g-group
o-others
a-all
u
Enter the permission we want to set
r-read
w-write
x-execute
r
The permission are as follows
-r-xr-xr-- 1 user user 35 Feb 5 00:33 file2
Do u want to continue(1 YES / 0 NO )
0
CONCLUSION:
The following script changes the attributes of file using chmod commands.
0 Comments