user@debian:~/test/B$ find ..
..
../A
../A/x
../A/y
../A/z
../B
user@debian:~/test/B$ find ../A -type f -print0 |xargs -0 -i% realpath --relative-to=../A %
x
y
z
user@debian:~/test/B$ # But
user@debian:~/test/B$ find ../A -type f -print0 |xargs -0 -i% echo $(realpath --relative-to=../A %)
../B/../A/x
../B/../A/y
../B/../A/z
Muru suggested that the answers to the question "find -exec command options with basename" might answer this question, but I'm not using find
with -exec
.
I don't understand muru's explanation "the command substitution around realpath
is executed by the shell before it even starts running xargs
(as a step in evaluating what the arguments to xargs
should be)":
- How can
realpath --relative-to=../A
be evaluated before the call toxargs
? - Even if it is evaluated, what does it evaluate to, and why does that lead to a different output?
basename
is executed by the shell before it even starts runningfind
(as a step in evaluating what the arguments tofind
should be). I'm not exactly sure whether that applies to my case as I'm not usingfind
with-exec
. – FriendFX Oct 17 '23 at 06:30find ... -print0 | xargs -0
is just a long-winded way of doingfind ... -exec
. – muru Oct 17 '23 at 06:32realpath
is executed by the shell before it even starts runningxargs
(as a step in evaluating what the arguments toxargs
should be)". – muru Oct 17 '23 at 06:36realpath --relative-to=../A %
in your shell to see what it is evaluated to. – muru Oct 17 '23 at 06:48%
can get substituted for thexargs
input from the output offind
. – FriendFX Oct 17 '23 at 06:51xargs
is not there to substitute it.%
is only special toxargs
, the shell will just use%
as it is. – muru Oct 17 '23 at 06:51