Issues on FIND

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
taersh
Posts: 951
Joined: Tue Jul 07, 2020 11:13 pm
Location: Germany
Has thanked: 53 times
Been thanked: 119 times

Issues on FIND

Post by taersh »

Hi.

I have a script to find files in a directory. Lately I found an issue using find. It doesn't seem to find anything anymore, if the slash on the end of the search path is missing.

This works:

Code: Select all

#!/bin/bash
rm -f /root/tmp/Win-VST-List.txt
Path="/root/Win-VST/"
Files=`find "$Path" -maxdepth 8`
echo "$Files" |while read F
do
	if [[ "$F" != "" && "$F" = *.so ]]; then
		#echo "$F"
		echo "`basename "$F"`"
		echo "`basename "$F"`" >>/root/tmp/Win-VST-List.txt
	fi
done

Though, this doesn't work (at least on my machine with Bionic64)

Code: Select all

#!/bin/bash
rm -f /root/tmp/Win-VST-List.txt
Path="/root/Win-VST"
Files=`find "$Path" -maxdepth 8`
echo "$Files" |while read F
do
	if [[ "$F" != "" && "$F" = *.so ]]; then
		#echo "$F"
		echo "`basename "$F"`"
		echo "`basename "$F"`" >>/root/tmp/Win-VST-List.txt
	fi
done

In my older Puppies e.g. Tahr it doesn't make a difference. Now I have to edit lots of my scripts. :cry:

When was this changed?

My Music:
https://soundcloud.com/user-633698367
Using my own build of Bionic64
The far-left is as fascist as the far-right is!

s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

Re: Issues on FIND

Post by s243a »

taersh wrote: Thu Jan 07, 2021 3:25 am

In my older Puppies e.g. Tahr it doesn't make a difference. Now I have to edit lots of my scripts. :cry:

When was this changed?

As a wild guess, might it depend on the version of find? For instance might there be subtle differences between the busybox and full version of find?

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 291 times

Re: Issues on FIND

Post by williams2 »

There is a big difference between a directory and a symbolic symlink to a directory. The symlink is a file and find will treat it as a file. A symlink with a trailing slash will be treated as a directory. For example, if /mnt/home is a symlink, then this:

find /mnt/home

is not the same as:

find /mnt/home/

It is a good idea to always have a trailing slash.

Post Reply

Return to “Programming”