In: Computer Science
Please find the bash script and execution screenshots below.
I have added all the comments for your better understanding.
#reading file/directory path upto its name into path variable
echo -n "Enter your file name or file path or directory name/path: "
read path
#checking whether file / directory exists or not
#if its present then we will print corresponding permissions
if [ -f "$path" ] || [ -d "$path" ]; then
echo "$path exists."
#checking for write permission
[ -w $path ] && W="Permission_to_Write = yes" || W="Permission_to_Write = No"
#checking for execute permission
[ -x $path ] && X="Permission_to_Execute = yes" || X="Permission_to_Execute = No"
#checking for read permission
[ -r $path ] && R="Permission_to_Read = yes" || R="Permission_to_Read = No"
echo -e "$path permissions : \n $W \n $R \n $X"
#if path is invalid then we will print does not exist
else
echo "$path does not exist in the given path."
fi
For file name abc.txt:
for directory: jjdj
for nested path: jjdj/x