bash -c versus dash -c

dash -cbehaves differently than 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 any explanation for this difference?

+4
source share
1 answer

bash has optimization when the most recent command in a script is implicitly executed with exec. Dash recently got this optimization, but not yet in the version you are using. You will see the same behavior with bash -c 'exec ps'and dash -c 'exec ps'.

+5
source

Source: https://habr.com/ru/post/1654256/


All Articles