0 Replies - 1199 Views - Last Post: 02 October 2010 - 03:05 PM Rate Topic: -----

#1 need_helpp   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 72
  • Joined: 08-September 09

UNIX:C shell script to implement a utility called junk..

Posted 02 October 2010 - 03:05 PM


I am very new to Unix environment.I am trying to write a C shell script to implement a utility called "junk" that satisfies the following specification:
junk -lp {pathname}*

junk is a replacement for the rm command. Rather than removing one or more files/directories, it moves them into a ~/.junk directory, which should be created if it does not exist. The -l option lists the current contents of the ~/.junk directory, and the -p option purges ~/.junk directory. junk could be called with no options (at least one pathname is required), with either option, or with both options (one or more pathname(s) are optional in the latter two cases).

I did some coding but I am not sure if I am on right track. Please advise me to the right direction.
Thank you.


if [ $#argv!= 1 ] then
echo "junk: One argument required" >&2
if [ ! -d $HOME/.junk ] then
mkdir $HOME/.junk
foreach 1(-l -p *)
switch ($1)
     case -l:
     ls -l $HOME/.junk | tail +2
     case -p:
     rm -r $HOME/.junk

     echo "junk: No write permission for file $1" >&2
     mv "$1" $HOME/.junk
     exit 0 

Is This A Good Question/Topic? 0
  • +

Page 1 of 1