如何将 at 命令 shell 从 sh 更改为 bash?
运行时at
,我收到以下消息warning: commands will be executed using /bin/sh
:
at 23:33
warning: commands will be executed using /bin/sh
我如何将默认 shell 设置/bin/bash
为/bin/sh
答案1
你不能改变默认shell 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");
实施来自atd.c
:
if (execle("/bin/sh", "sh", (char *) NULL, nenvp) != 0)
手册页如下:
at 和 batch 从标准输入或指定文件读取稍后执行的命令,使用/bin/sh。
这使得您必须重新编译自己的副本作为满足您需求的唯一解决方案。
答案2
看着man at
,好像你不能改变外壳。
at
但是,您也可以在SH shell内的 Bash shell 中启动命令,如下所示:
at 01:23 <<< "bash -c 'notify-send \"running from $SHELL\"'"