Re: new to shell scripting

joe_at_invalid.address
Date: 07/22/05

  • Next message: David Schwartz: "Re: Practice of using fork()"
    Date: 22 Jul 2005 00:02:57 -0500
    
    

    "James" <bob_then@yahoo.com.au> writes:

    > I am new to shell scripting and trying to learn bourne shell
    > scripting I was try to write a script that check the content of
    > directory A and B and deletes any files in A that are not in B
    >
    > So far I have
    >
    > #!/bin/sh
    > for d in dirB/*; do
    > if [ -f dirA/$d ]
    > then
    > echo "$d"
    > fi
    > done
    >
    > I used echo instead of rm because I am new to shell script and
    > didn't want to delete all my files.

    That's a good way to test things. Another way is to try the parts of
    the script on the command line. In this case,

    $ for d in dirB/*;do echo "$d";done

    would show you that "dirB/" is part of what's returned. What you want
    d to be is just the file name. That can be gotten with the basename
    command. Try instead

    for d in dirB/*; do
      d=`basename "$d"`
      if [ -f dirA/"$d" ]
      then
        echo "$d"
      fi
    done

    Joe


  • Next message: David Schwartz: "Re: Practice of using fork()"

    Relevant Pages