iiitl / bash-practice-repo-24

0 stars 35 forks source link

#6 Added perms script #114

Closed Priyanshu-2005 closed 5 months ago

Priyanshu-2005 commented 5 months ago

Fixes #6 Added the perms script

This script takes a certain set of filenames as input and displays their permission in octal format if they exist.

OUTPUT Commands used ls -a bash perms <filename1> <filename2> <filename3>...... image

Command used bash perms image

Explanation of the code

for file in "$@"; do Checks for all the files given in arguments

if [ -e "$file" ]; then Checks for existence of the file in the present working directory

permissions=$(stat -c "%a" "$file") Retrieves the permissions of a file and assigns them to the variable permissions.

echo "Permissions of '$file' in octal format: $permissions" Displays the permissions of the file in octal format

echo "File '$file' does not exist." If the file is not present in the present working directory then displays that Fille does not exist

list_permissions "$@" Calls the list_permission function

Explanation of the Output If the script displays the permissions as 775 that means

ecxtacy commented 5 months ago

Good work @Priyanshu-2005.