0

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.

2

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 2 '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). – mosvy Dec 2 '18 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.