If and Decision making is done

This commit is contained in:
Hizenberg469
2024-11-29 13:25:36 +05:30
parent 5759f3f807
commit 1ede16f3c4
4 changed files with 225 additions and 1 deletions

49
filetest.sh Normal file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
#for provided file print the summary of what permissions users has granted
#example: ./filetest.sh hello.txt
#READ: YES
#WRITE: NO
#EXECUTABLE:NO
#argument check
if [ $# -ne 1 ]; then
echo "Provide exactly one argument"
exit 1
fi
#variable assignment
FILE=$1
#check if the file exists
if [ -f $FILE ]; then
#default variables
VAR_READ="NO"
VAR_WRITE="NO"
VAR_EXEC="NO"
#check if file is readable
if [ -r $FILE ]; then
VAR_READ="YES"
fi
#check if file is writable
if [ -w $FILE ]; then
VAR_WRITE="YES"
fi
#check if file is executable
if [ -x $FILE ]; then
VAR_EXEC="YES"
fi
#write permissions summary to user
echo "==FILE: $FILE=="
echo "READ: $VAR_READ"
echo "WRITE: $VAR_WRITE"
echo "EXECUTABLE: $VAR_EXEC"
else
echo $FILE does not exists
fi