Here is a "c" shell script I wrote some time ago:
#! /bin/csh
set IPCS="/usr/bin/ipcs"
set SED="/usr/bin/sed"
set GREP="/usr/bin/grep"
set IPCRM="/usr/bin/ipcrm"
switch($1)
case "-m":
set string="Parsing Shared Memory:"
breaksw
case "-s":
set string="Parsing Semaphores:"
breaksw
case "-q":
set string="Parsing Message Queues:"
breaksw
default:
echo "USAGE: ipcsrm [-m|-s|-q] [-u {username} | -g {groupname}] "
exit
endsw
switch($2)
case "-u":
set string="$string looking for username <$3> and removing"
breaksw
case "-g":
set string="$string looking for groupname <$3> and removing"
breaksw
default:
echo "USAGE: ipcsrm [-m|-s|-q] [-u {username} | -g {groupname}] "
exit
endsw
set limit=$3
echo $string
foreach ent ( `$IPCS $1 | $GREP $limit | $SED 's/ /+/g'` )
set entry=`echo $ent | $SED 's/+/ /g'`
set addr=`echo $entry | awk '{ print $2 }'`
if( $2 == "-u" ) then
if( $3 == `echo $entry | awk '{ print $5 }'` ) then
$IPCRM $1 $addr
endif
else if( $2 == "-g" ) then
if( $3 == `echo $entry | awk '{ print $6 }'` ) then
$IPCRM $1 $addr
endif
endif
end