Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

raku

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.

like image 315
brian d foy Avatar asked Apr 25 '18 19:04

brian d foy


Video Answer


2 Answers

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

like image 61
timotimo Avatar answered Oct 19 '22 05:10

timotimo


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.

like image 37
ikegami Avatar answered Oct 19 '22 07:10

ikegami