Results 1 to 6 of 6
i have just started out scripting and have some doubts ,
1) How do i print the file access permission(FAP) for all the type of users ??
2) how to ...
- 04-26-2007 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
Bash shell scripting doubts
i have just started out scripting and have some doubts ,
1) How do i print the file access permission(FAP) for all the type of users ??
2) how to search for files with same name in current directory ?
3) how do i validate a blank user input ? like if user doesnt enter any values and presses Enter, what condition do i put in an If construct ?
4) how to check what files were created today ? ls shows only the last modification date.
thnx for reading the post.
- 04-27-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
It's against the rules to post homework here.
Google on "howto bash scripting"
Regards
- 04-27-2007 #3Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
- 04-27-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Ok, what have you tried so far?
And what goes wrong?
Regards
- 04-28-2007 #5Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
well, by some research and trial n error i have solved most of the doubts to an extent ,
1)for the FAP problem , i did this,
the output is :Code:echo -n "Enter Filename : " ; read fname ; # check if file exists if [ -e $fname ] then #display fap for owner echo "Owner" ls -l $fname|awk '{print $1 }' |tee temp | cut -c2-4 #display fap for group users echo "Group" cat temp | cut -c5-7 #display fap for other users echo "Other" cat temp | cut -c8-10 else echo "FIle does not exist" fi
Now, this is an acceptable output , but i want to print the words "Read" "Write" "Execute" instead of 'rwx'. If it were only for the owner , i could use the test command and -r, -w, -x options but that doesnt work for Group and Other users, how do i do that ?Code:Owner rwx Group r-x Others r--
- 04-28-2007 #6Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
An example:
I've use a function to print out the permissions.Code:#!/bin/sh Permission() { for((i=0; i<3; i++)) do case ${perm:i:1} in "r") printf "Read\t" ;; "w") printf "Write\t" ;; "x") printf "Execute\t" ;; esac done echo } echo -n "Enter Filename : " ; read fname if [ ! -e $fname ] ; then echo File $fname does not exist exit 1 fi fileperm=`ls -l $fname` # I don't use a loop here to show the use of substrings # The function Permission is called 3 times echo Owner perm=${fileperm:1:3} Permission echo Group perm=${fileperm:4:3} Permission echo Others perm=${fileperm:7:3} Permission exit 0
It's not an easy example for a beginner but spend some time to find out how it works, go here for some tutorials:
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://tldp.org/LDP/abs/html
Regards


Reply With Quote

