Hi all,
I wish to write a script using getopts to allow me to change permissions,
owner & group on a file or multiple files by supplying different options and
arguments to it.
I'm a newbie, so take it easy on me...haha ;-)
so far my code is as such:
I've actually called this script 'mychmod', same as the function name and
FPATH is set in my .profile file.
mychmod()
{
while getopts p:o:g: option # p=permissions o=owner g=group
do
case ${option} in
p ) chmod_opt=${OPTARG};p_opt=yes;;
o ) chown_opt=${OPTARG};o_opt=yes;;
g ) chgrp_opt=${OPTARG};g_opt=yes;;
esac
done
shift `expr ${OPTIND} - 1`
do
test "${p_opt} = "yes" && chmod "${chmod_opt}" $file
test "${o_opt} = "yes" && chown "${chown_opt}" $file
test "${g_opt} = "yes" && chgrp "${chgrp_opt}" $file
done
if I test the script for syntax errors using 'ksh -n mychmod', there aren'tQuote:}
any errors.
#echo "this is a dummy file" > dummy
When I run the function, it spits out the following error:-
#mychmod -p 777 dummy
usage: chmod [-fR] <absolute-mode> file ...
chmod [-fR] <symbolic-mode-list> file ...
where <symbolic-mode-list> is a comma-separated list of [ugoa] {+|-|=}
[rwxXlstugo]
Cannot open file
What am I missing? Or what does the above error mean? Your help is very
much appreciated.
Thanks