Which shell does Perl 6's shell() use?

百般思念 提交于 2020-06-27 07:13:12

问题


Perl 6's shell sends commands to the "shell" but doesn't say what that is. I consistently get bash on my machine but I don't know if I can rely on that.

$ perl6 -e 'shell( Q/echo $SHELL/ )'
/bin/bash
$ csh
% perl6 -e 'shell( Q/echo $SHELL/ )'
/bin/bash
% zsh
$ perl6 -e 'shell( Q/echo $SHELL/ )'
/bin/bash

That's easy enough on Unix when it's documented, but what about cmd.exe or PowerShell on Windows (or bash if it's installed)? I figure it's the cmd.exe but a documented answer would be nice.


回答1:


Looking at the the source, rakudo just calls /bin/sh -c on non-windows and uses %*ENV<ComSpec> /c on windows.




回答2:


dash (installed as /bin/sh on many systems), doesn't set $SHELL, nor should it. $SHELL isn't the name of the parent process; it's the name of the shell that should be used when an interactive shell is desired.

To get the name of the parent process, you could use the following on some systems:

echo "$0"

or

# Command line
perl -e'$ppid=getppid(); @ARGV="/proc/$ppid/cmdline"; CORE::say "".<>'

or

# Program file
perl -e'$ppid=getppid(); CORE::say readlink("/proc/$ppid/exe")'

You'll find you'll get /bin/sh in all cases.



来源:https://stackoverflow.com/questions/50029941/which-shell-does-perl-6s-shell-use

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!