FirstMan
asked on
permissions problem
My Question
I want to create a shell script called 'permissions' which takes a file as an argument. The script should be able to determine what permissions the owner, group and everybody has for the file passed in.
The output of this script should resemble this:
READ WRITE EXECUTE
OWNER ADAM.ADEBISI YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO
so far i have done this:
#!/bin/bash
perm=$(ls -l $1 | cut -f1 -d" ")
group=$(ls -l $1 | cut -b26-32 )
owner=$(ls -l $1 | cut -b17-23)
or=$(echo $perm | cut -b2)
ow=$(echo $perm | cut -b3)
ox=$(echo $perm | cut -b4)
gr=$(echo $perm | cut -b5)
gw=$(echo $perm | cut -b6)
gx=$(echo $perm | cut -b7)
er=$(echo $perm | cut -b8)
ew=$(echo $perm | cut -b9)
ex=$(echo $perm | cut -b10)
echo "For file: $1"
echo -e "\t\tREAD\tWRITE\tEXEC"
echo -e "\t\t----\t-----\t----"
echo -e "$owner\t\t$or\t$ow\t$ox"
echo -e "$group\t\t$gr\t$gw\t$gx"
echo -e "other\t\t$er\t$ew\t$ex"
but the output is not what i predicted
For file:
READ WRITE EXEC
---- ----- ----
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
where am i going wrong?
I want to create a shell script called 'permissions' which takes a file as an argument. The script should be able to determine what permissions the owner, group and everybody has for the file passed in.
The output of this script should resemble this:
READ WRITE EXECUTE
OWNER ADAM.ADEBISI YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO
so far i have done this:
#!/bin/bash
perm=$(ls -l $1 | cut -f1 -d" ")
group=$(ls -l $1 | cut -b26-32 )
owner=$(ls -l $1 | cut -b17-23)
or=$(echo $perm | cut -b2)
ow=$(echo $perm | cut -b3)
ox=$(echo $perm | cut -b4)
gr=$(echo $perm | cut -b5)
gw=$(echo $perm | cut -b6)
gx=$(echo $perm | cut -b7)
er=$(echo $perm | cut -b8)
ew=$(echo $perm | cut -b9)
ex=$(echo $perm | cut -b10)
echo "For file: $1"
echo -e "\t\tREAD\tWRITE\tEXEC"
echo -e "\t\t----\t-----\t----"
echo -e "$owner\t\t$or\t$ow\t$ox"
echo -e "$group\t\t$gr\t$gw\t$gx"
echo -e "other\t\t$er\t$ew\t$ex"
but the output is not what i predicted
For file:
READ WRITE EXEC
---- ----- ----
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
where am i going wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It nearly works for me - you'll have to trace what is happening in your case. I added the following lines:
echo perm=$perm
echo group=$group
echo owner=$owner
You may wish to deal with the case of no parameter ($1) being passed, in which "ls -l" is run without parameter - your cuts will look at the first line, which in my system is a total number of files displayed. The other case is a wildcard (eg '*').
echo perm=$perm
echo group=$group
echo owner=$owner
You may wish to deal with the case of no parameter ($1) being passed, in which "ls -l" is run without parameter - your cuts will look at the first line, which in my system is a total number of files displayed. The other case is a wildcard (eg '*').
ASKER