help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CL function to script difficulties


From: Greg Wooledge
Subject: Re: CL function to script difficulties
Date: Fri, 19 Apr 2024 17:06:36 -0400

On Fri, Apr 19, 2024 at 04:52:12PM -0400, Greg Wooledge wrote:
> On Fri, Apr 19, 2024 at 03:15:07PM -0500, Mike McClain wrote:
> > This function defined on the command line works as I wish:
> > dircmp() {
> >     diff <(cd $1; find . -type f,l,d -printf '%p %s %t\n' | sort) \
> >          <(cd $2; find . -type f,l,d -printf '%p %s %t\n' | sort);
> > }

I should have included this in the previous reply:

Your parameter expansions $1 and $2 should be double-quoted.  Otherwise,
they won't work when one of your directory arguments contains whitespace.

Also, the cd command could fail.  If this happens, your find command
will run in the current directory, instead of the directory you asked
for.  Unfortunately, it's not easy to fix this, because you've got two
independent background processes running simultaneously, and if one of
them fails, the other might not.  The most immediate solution I can offer
is:

dircmp() {
    diff <(cd "$1" && find . -type f,l,d -printf '%p %s %t\n' | sort) \
         <(cd "$2" && find . -type f,l,d -printf '%p %s %t\n' | sort)
}

If one of the cds fails, then its find command will not run, and you'll
get a blank list as one of diff's arguments.  That's probably the best
you can hope for in this situation.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]