Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 2
    The sed is fine with whitespace, and the cd (which you don't need, by the way) just needs a quoted variable. It's the loop that parses the output of find that needs improvement. What operating system are you using? Do you have GNU find? Does your find have a -print0 or -printf option? Commented Jun 27, 2022 at 21:31
  • 2
    Also, any args with spaces, tabs, shell metachars in them must be quoted (or appropriately escaped) when passed to the script or function. Commented Jun 28, 2022 at 5:19
  • 2
    Does this answer your question? When is double-quoting necessary? Commented Jun 28, 2022 at 11:52
  • 2
    See also: Why is looping over find's output bad practice? and Understanding "IFS= read -r line" Commented Jun 28, 2022 at 12:20
  • 1
    How do you want to handle cases where you have more than one matching directory? For example, if vfind=foo and vreplace=bar and you have a directory called foo which is a subdirectory of another called foo (/whatever/foo/something/foo). Do we need to be able to handle such cases? Commented Jun 28, 2022 at 13:19