如何将 at 命令外壳设置为 bash?

use*_*456 7 command-line cron

如何将 at 命令外壳从 sh 更改为 bash?

运行时at,我收到消息warning: commands will be executed using /bin/sh

at 23:33                                                              
warning: commands will be executed using /bin/sh
Run Code Online (Sandbox Code Playgroud)

如何将默认外壳设置为/bin/bash而不是/bin/sh

hee*_*ayl 7

您无法更改 的默认外壳at,它/bin/sh与源代码中一样是硬编码的。

的源代码at阐明了这一点,来自at.c

    /* POSIX.2 allows the shell specified by the user's SHELL environment                                                           
       variable, the login shell from the user's password database entry,                                                                
       or /bin/sh to be the command interpreter that processes the at-job.                                                               
       It also alows a warning diagnostic to be printed.  Because of the                                                                
       possible variance, we always output the diagnostic. */

    fprintf(stderr, "warning: commands will be executed using /bin/sh\n");
Run Code Online (Sandbox Code Playgroud)

实施,来自atd.c

if (execle("/bin/sh", "sh", (char *) NULL, nenvp) != 0)
Run Code Online (Sandbox Code Playgroud)

手册页相应地符合:

at 和批处理从标准输入或指定文件读取命令,这些命令将在稍后执行,使用/bin/sh

这让您重新编译自己的副本,作为满足您需求的唯一解决方案。

  • 嗯...他还可以将 `bash` 符号链接到 `/bin/xy`(或任何 7 个字符或更短的绝对路径名),并在编译的 `at` 二进制文件中手动编辑正确的 `/bin/sh` 字符串为成为新路径(不真正推荐给不习惯十六进制编辑二进制文件的任何人,但可能)。 (4认同)

Byt*_*der 5

看着man at,好像不能换壳了。

但是,您可以在at的 SH shell内的 Bash shell 中启动您的命令,如下所示:

at 01:23 <<< "bash -c 'notify-send \"running from $SHELL\"'"
Run Code Online (Sandbox Code Playgroud)