0

From https://unix.stackexchange.com/a/156010/674

Note that the second sh above goes into the inline script's 0ドル. You should use something relevant there (like sh or find-sh), not things like _, -, -- or the empty string as that is used for the shell's error messages:

$ find . -name accept_ra -exec sh -c 'echo 0 > "1ドル"' inline-sh {} \;
inline-sh: ./accept_ra: Permission denied

What does "_, -, -- or the empty string is used for the shell's error messages" mean?

Why does using inline-sh not work in the example, given that inline-sh is not _, -, -- or the empty string?

Thanks.

asked Jun 8, 2018 at 13:15

2 Answers 2

7

The subject of "is used for the shell’s error messages" is "0ドル", not "_, -, -- or the empty string". The value given to 0ドル is used for error messages; so you shouldn’t specify a meaningless value for 0ドル, otherwise you’ll end up with weird error messages. It might make more sense as

Note that the second sh above goes into the inline script's 0ドル. You should use something relevant there (like sh or find-sh), not things like _, -, -- or the empty string, as the value in 0ドル is used for the shell's error messages:

inline-sh does work in the example: it’s used in the error message, which is the whole point of the example.

Stéphane Chazelas
582k96 gold badges1.1k silver badges1.7k bronze badges
answered Jun 8, 2018 at 13:22
0
6
$ find . -name accept_ra -exec sh -c 'echo 0 > "1ドル"' inline-sh {} \;
inline-sh: ./accept_ra: Permission denied

The error message tells you it's an inline-sh that fails to open a ./accept_ra file.

$ find . -name accept_ra -exec sh -c 'echo 0 > "1ドル"' _ {} \;
_: ./accept_ra: Permission denied
$ find . -name accept_ra -exec sh -c 'echo 0 > "1ドル"' '' {} \;
: ./accept_ra: Permission denied

Makes it less obvious and more confusing to the user what is actually failing to open that ./accept_ra.

Hence the recommendation to use a meaningful value for that first argument after sh -c 'code'. Repeating the command name is generally just fine. As in

sh -c 'code using "$@"' sh actual arguments to the inline script
answered Jun 8, 2018 at 13:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.