Search code examples
bashubuntudash-shell

"bash -c" vs. "dash -c"


dash -c behaves differently from bash -c:

docker run -it ubuntu /bin/dash -c ps
  PID TTY          TIME CMD
    1 ?        00:00:00 sh
    7 ?        00:00:00 ps

docker run -it ubuntu /bin/bash -c ps
  PID TTY          TIME CMD
    1 ?        00:00:00 ps

Is there an explanation for this difference?


Solution

  • bash has an optimisation where the very last command in a script implicitly gets executed with exec. dash recently gained this optimisation as well, but not yet in the version you're using. You'll see the same behaviour with bash -c 'exec ps' and dash -c 'exec ps'.