Warning using 'find'.

This is more of a discovery than a bug and for OSX 10.12.x, maybe earlier but I don't have them now.

Consider this code:-

		# Auto-find the correct path and "sox" file, but it WILL take a very long time...
		# NOTE: It searches from YOUR HOME directory structure only, just modify to suit your machine if 'SOX' is elsewhere.
		capturepath=$(find "$HOME" -name 'sox' 2>/dev/null)

This works perfectly with a virgin install of SOX, (in this case inside my $HOME directory).
I decided to install the latest version of SOX 14.4.2.
I then placed the original into the "Trash", that is "$HOME"/.Trash/ directory.
Next I launched "./AudioScope.sh" and as expected DEMO worked perfectly.
THEN; I decided to run the SOX command inside the code and the code literally crashed out.
The error report pointed to "$HOME/.Trash/sox-14.4.0/sox" so it looks as though the 'find' command searches the "$HOME"/.Trash/ directory also.
Unlike the AMIGA, OSX cannot run code from inside its Trashcan hence the total crashout.
So let this be a warning to others if you have a previous version of something in the Trashcan and another version elsewhere and you intend to find it using the 'find' command then EXPECT a bug as "$HOME"/.Trash/ is searched early in the scan.

I hope this is useful to others.

Bazza...

Just exclude the .Trash directory in your find statement.

find "$HOME" -path '*.Trash*' -prune -o \( -name sox -print \)
1 Like

Get used to the following, that will skip "hidden" directories like .Trash/ .git/ .snapshot/ .Wastebasket/ ...

find "$HOME" -type d -name '.?*' -prune -o -type f -name 'sox' -print

Note the -print is important. Otherwise it defaults to also print the pruned directories!

2 Likes

Thanks guys.

Will update code soon...

I never guessed that the '.Trash' folder would be searched...

Hi MadeInGermany...

Many thanks the code works superbly...

I have acknowledged your input inside the Manual section of AudioScope.sh...

<Thumbs Up sign here...>

Try character sequence :b: in your post.

:b:

Kind regards,
Robin

1 Like

but you will stuff if it's buried in a places like .cpan .R .conda

It is a - quite common - misconception to think that files/directories which names start with a dot are somehow special. They are not. In fact the only "special treatment" they receive is by the ls -command which does not display them as long as the option -a (display them anyway) is not given.

For all other commands (including find ) directories and/or filenames starting with a dot a just as normal as all the others. If you want to exclude them from your result set you have to take specific precautions to filter them out. For the same reason:

rm ..

might not do what you wanted/expected it to do, but syntactically the command is OK and - given the right privileges - will do what it is supposed to do (which, again, might not be what you wanted, but that is another problem).

I hope this helps.

bakunin

In addition to ls , hidden files (i.e., files with a <period> as the first character of their name) are not found using the asterisk in the shell as a filename matching pattern unless you explicitly include <period> as the first character in the pattern. For example:

echo 'unhidden files:'
printf '"%s"\n' *
printf '\n\nhidden files:'
printf '"%s"\n' .*

prints two distinct sets of files