bash - "bash -c"与 "dash -c"

标签 bash ubuntu dash-shell

dash -cbash -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

对这种差异有解释吗?

最佳答案

bash 有一个优化,其中脚本中的最后一个命令隐式地用 exec 执行。 dash 最近也获得了这种优化,但还没有在您使用的版本中。您将看到 bash -c 'exec ps'dash -c 'exec ps' 的相同行为。

关于bash - "bash -c"与 "dash -c",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39434493/

相关文章:

unix - 如何在 ubuntu 中从 root 设置 cron?

bash - 在 POSIX shell 脚本中嵌入 Unicode 字符的最佳方法是什么?

bash:无法在同一行中设置和使用别名

git - 在 bash 脚本中按模式过滤行

bash - 将 linux "cut"与标准输入一起使用

linux - 如何在 java-ee web 应用程序中运行 bash 脚本?

bash - 如何找到一个字符串以及给定字符串的上下行数

php - 尝试访问本地 LAMP 服务器上的 localhost 时出现 404 Not Found 错误

php - apache root 中文件的 770 权限,仍然可见

linux - 狂欢 : "done" unexpected (expecting "fi")