Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;bash-c";vs.“;破折号-c“;_Bash_Ubuntu_Dash Shell - Fatal编程技术网

&引用;bash-c";vs.“;破折号-c“;

&引用;bash-c";vs.“;破折号-c“;,bash,ubuntu,dash-shell,Bash,Ubuntu,Dash Shell,dash-c的行为不同于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 对于这种差异有什么解释吗?ba

dash-c
的行为不同于
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

对于这种差异有什么解释吗?

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

中看到相同的行为,我认为bash不需要运行shell来运行ps。