akvino
March 17th, 2009, 03:48 PM
Hello all. I am trying to write a script in C shell, that would check for the current directory and based on which directory it is, allow or dissalow 'rm' command.
My biggest problem so far is checking if the directory "pwd" is resstricted or not. Here is my code where I do pattern matching:
set localdir=`pwd`;
echo "$localdir" ;
if ("$localdir" == '/root') then
echo "this is your root directory";
exit
end if
if ( "$localdir" =~ *[go] ) then
echo "You are not allowed 1 delete files in $localdir!";
exit
else if ( "$localdir" =~ *[qff] ) then
echo "You are not allowed 2 delete files in $localdir!";
exit
else if ( "$localdir" =~ *[fone] ) then
echo "You are not allowed 3 delete files in $localdir!";
exit
endif
-----------------------
ANy of the named directories could have different path - for instance:
path1/go
path2/go
path3/go
etc...
What I have noticed, when I add data directory - it also dissalows root directory so the code:
if ( "$localdir" =~ *[data] ) then
echo "You are not allowed 3 delete files in $localdir!";
exit
endif
IS THE SAME AS:
if ( "$localdir" =~ *[root] ) then
echo "You are not allowed 3 delete files in $localdir!";
exit
endif
---------------------------------------
My question - what is the better way to implement pattern matching into this code? How does C shell interpret these pattern matching conditional statments (does it first convert them to binary?)
My biggest problem so far is checking if the directory "pwd" is resstricted or not. Here is my code where I do pattern matching:
set localdir=`pwd`;
echo "$localdir" ;
if ("$localdir" == '/root') then
echo "this is your root directory";
exit
end if
if ( "$localdir" =~ *[go] ) then
echo "You are not allowed 1 delete files in $localdir!";
exit
else if ( "$localdir" =~ *[qff] ) then
echo "You are not allowed 2 delete files in $localdir!";
exit
else if ( "$localdir" =~ *[fone] ) then
echo "You are not allowed 3 delete files in $localdir!";
exit
endif
-----------------------
ANy of the named directories could have different path - for instance:
path1/go
path2/go
path3/go
etc...
What I have noticed, when I add data directory - it also dissalows root directory so the code:
if ( "$localdir" =~ *[data] ) then
echo "You are not allowed 3 delete files in $localdir!";
exit
endif
IS THE SAME AS:
if ( "$localdir" =~ *[root] ) then
echo "You are not allowed 3 delete files in $localdir!";
exit
endif
---------------------------------------
My question - what is the better way to implement pattern matching into this code? How does C shell interpret these pattern matching conditional statments (does it first convert them to binary?)