Write script which will get filename as param

April 21, 2010 at 05:30:25
Specs: Linux i686
Write script which will get filename as parameter
and will show file rights for
current user (rwx rights). Filename should be
given as parameter in command line.
Script should check if this parameter is given.

I need help about this question..! Thanks


See More: Write script which will get filename as param

Report •

#1
April 21, 2010 at 07:35:48
Here's a script I wrote as an assignment while doing a UNIX course. It's not exactly what you're looking for, but, if you copy and paste it into a script you can see how it runs and then make the necessary changes to show what's required for your homework question:

#!/bin/sh
if [ $# -eq 0 -o $# -gt 1 ]
        then
                echo "Usage: $0 ordinary_file"
                exit 1
fi
if [ -f "$1" ]
        then
               if [ -s "$1" ]
                   then
                          filename="$1"
                          set `ls -iol $filename`
                          echo "Filename: $filename  Size: $1  No. of Hard Links: $3  Owner: $4    Date last modified: $8/$9"
                   else
                          filename="$1"
                          echo "Zero byte file (empty) - deleting file"
                          rm -f $filename
                          exit 2
               fi
        else
               usage "$0: arguement must be an ordinary file"
fi
exit 0





Report •
Related Solutions


Ask Question