mirror of
https://github.com/Hizenberg469/Makefile-tutorial.git
synced 2026-04-19 22:02:24 +03:00
50 lines
904 B
Bash
50 lines
904 B
Bash
#!/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
|