1

I would like to find some directories via

find /path/to/a/dir -type d  -links 2 

and then for each pathname found by find, assumed to be stored in variable pathname, I would like to

stow -d "$(dirname "$pathname")" -t /home/t/bin "$(basename "$pathname")" 

How can I combine the above with find -exec, something similar to:

find /path/to/a/dir -type d  -links 2 -exec stow -d "$(dirname \{\})" -t /home/t/bin "$(basename \{\})" \;

I think it doesn't work because the shell performs the command substitutions before running find, and no pathname is found yet to replace \{\} in the command substitutions.

Thanks.

Tim
  • 98,580
  • 191
  • 570
  • 977

1 Answers1

3

You wrap it in a sh -c command

find /path/to/dir -type d -links 2 -exec sh -c 'stow -d "$(dirname "$1")" -t /home/t/bin "$(basename "$1")"' sh {} \;
  • Thanks. Why do you use `sh` instead of `bash` here? – Tim Dec 02 '18 at 14:14
  • `sh` is guaranteed to exist on any Unix system. On `linux`, `/bin/sh` is either a symlink to `/bin/bash` itself (eg. rhel, centos) or to something smaller and faster (`/bin/dash` on ubuntu and debian). –  Dec 02 '18 at 14:28