I want to specify a variable in the path of find

Asked 2 months ago, Updated 2 months ago, 3 views

Thank you for your hard work.

Let's say the following code is the main subject.


file_name = test.txt

while read line;do
    dir = ${line}

    while read;do
         echo "Verify operation: ${red}"
     done<<(find${dir}-type f)


Doing so will result in the error Find: 'Directory Name': No such file or directory.

How do I resolve this?

The test.txt contains the directory path.
I would like to specify it as the path to find and search for files below that directory.

    dir = "Directory Path"
    while read;do
         echo "Verify operation: ${red}"
    done<<(find${dir}-type f)

If you write like above, it will work.

When I see the error message, it seems that something is stuck together, but I don't know how to deal with it.

Thank you for your cooperation.

bash shellscript

2022-09-30 11:59

2 Answers

find(1) displays such a warning that the path to be scanned does not exist. All you have to do is check if it exists before passing it to find.


while IFS = read-rd; do
  [[-d$d]]|| continue
  find "$d" - type f-exec sh-c' for file in "[email protected]"; do echo "Verify operation:$f"; done'sh{}+

2022-09-30 11:59

Try connecting the find command to ` instead of ().
Excerpt only the relevant parts…

while read;do
    echo "Verify operation: ${red}"
done<`find${dir}-type f`

Run Environment
bash 3.2
RHEL 5.11

2022-09-30 11:59

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.