0

What is the use of the underscore _ in the find command below which is a command to create a file in all directories?

find . -type d -exec sh -c 'echo "nameofyourwebsite" > "$1"' _ {}/downloaded.txt \;

And if {} is a placeholder that is holding the directory names then why is the echo command redirecting to $1?

or $1 is first argument which is {}/downloaded.txt ?

Please explain in the simplest way how this command is working.

Sadam
  • 107
  • 2
  • 9
  • 1
    Btw: `sh` ([Bourne-shell](https://en.wikipedia.org/wiki/Bourne_shell)) is usally not `bash` ([Bourne-again shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell))). – Cyrus Mar 26 '22 at 19:04
  • 2
    This all has to do with how `sh -c` works -- see my answer to [this Ask Different question](https://apple.stackexchange.com/questions/384219/difference-in-executing-a-command-line-in-a-different-ways) – Gordon Davisson Mar 26 '22 at 19:26
  • 1
    See also [this answer](https://stackoverflow.com/a/5121324/3266847). – Benjamin W. Mar 26 '22 at 19:52
  • 1
    Try `sh -c 'echo "$0"' _`. – chepner Mar 26 '22 at 21:49
  • @GordonDavisson i can't comment there due to low rep. one question you mentioned that But what's that ```installer-thingie``` argument? That's the name the mini-script is run under, so it'll show up as ```$0``` inside the mini-script. Basically, it functions as a placeholder, and you could put pretty much anything there. what if i change this to ```installer-thingie``` any random name or my name is there any effect on command output or i can type anything here – Sadam Mar 27 '22 at 04:02
  • 1
    @Sadam You can change it to any random name; it won't have any effect unless the mini-script refers to `$0`. – Gordon Davisson Mar 27 '22 at 04:08

0 Answers0