1

I am going through ,this answer here Understanding the -exec option of `find`

I am not able to understand, how below piece of code works

sh -c 'echo "hello $1" ' somestring works

How does that work,if i remove somestring ,it doesn't even work..

I tried searching with keywords like sh -c examples,but its not yielding any results

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
TheGameiswar
  • 115
  • 5
  • 2
    [What is the second sh in `sh -c 'some shell code' sh`?](https://superuser.com/q/1526229/432690) – Kamil Maciorowski Sep 13 '22 at 03:40
  • In your case, `somestring` will be the name of the script. Try using: `sh -c 'echo -e "Filename: $0\nhello $1" ' `. The first argument after sh -c '...' it's the name of the script and the following values are the parameters passed to that script. You should check the link that @KamilMaciorowski provided. – Edgar Magallon Sep 13 '22 at 03:56
  • Thank you both for your time and help – TheGameiswar Sep 13 '22 at 04:27
  • 1
    See [Bash -c with positional parameters](https://unix.stackexchange.com/q/152391/170373) – ilkkachu Sep 13 '22 at 05:11

0 Answers0