Hello,
On 2023/03/29 22:39:52 +0800, lux <[email protected]> wrote:
> Hi, the name of the shell subprocess is hardcoded in the `script'
> command.
>
> The test is as follows:
>
> $ echo $SHELL
> /bin/ksh
> $ script -c 'echo $0'
> Script started, output file is typescript
> sh <---- The correct one should be 'ksh'
> Script done, output file is typescript
>
> I fixed.
I'm not sure your fix is correct.
Unlike the similar issue in mg, $SHELL here is only used in case no -c
flag was given and an interactive one is spawned
331 execl(shell, shell, "-i", (char *)NULL);
In the other case (script -c) /bin/sh is used *unconditionally*
328 execv(_PATH_BSHELL, argp);
If you don't trust my words, here's an example: (running with your
patch applied)
% SHELL=/bin/bash ./obj/script -c 'echo $0'
Script started, output file is typescript
bash
Script done, output file is typescript
% file /bin/bash
/bin/bash: cannot stat '/bin/bash' (No such file or directory)
There's no /bin/bash but script -c succeeded. Why? Because it always
runs /bin/sh when invoked with the -c flag!
Furthermore, the man page explicitly states that script -c runs sh(1):
-c command
Run sh -c command, instead of an interactive shell. [...]
So I'd say that script(1) is working as intended. What was exactly
the issue that you were trying to solve?