mirror of
https://github.com/Hizenberg469/Makefile-tutorial.git
synced 2026-04-19 22:02:24 +03:00
If and Decision making is done
This commit is contained in:
49
filetest.sh
Normal file
49
filetest.sh
Normal 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
|
||||
Reference in New Issue
Block a user