How do I change the at command shell from sh to bash?

When running at, I recieve the message warning: commands will be executed using /bin/sh:

at 23:33                                                              
warning: commands will be executed using /bin/sh

How can I set the default shell to /bin/bash instead of /bin/sh


Looking at man at, it seems like you can't change the shell.

However, you could just launch your commands inside a Bash shell inside at's SH shell, like this:

at 01:23 <<< "bash -c 'notify-send \"running from $SHELL\"'"
| improve this answer | |

You can't change the default shell of at, it is hardcoded as /bin/sh in the source.

The source code of at clarifies this, from 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");

Implementation, from atd.c:

if (execle("/bin/sh", "sh", (char *) NULL, nenvp) != 0)

The man page conforms accordingly:

at and batch read commands from standard input or a specified file which are to be executed at a later time, using /bin/sh.

That leaves you to recompile your own copy as the only solution to meet your need.

| improve this answer | |
  • 4
    Well... he could also symlink bash to /bin/xy (or any 7-character or shorter absolute pathname), and manually edit the correct /bin/sh string in the compiled at binary to be the new path (not really recommended to anyone who isn't comfortable hex-editing binaries, but possible). – mtraceur Oct 3 '16 at 1:19
  • @mtraceur Or that ;) – heemayl Oct 3 '16 at 4:29
  • 1
    @mtraceur This seems flimsy especially if the string is interned once but has multiple uses -- my point is, the source should be recompiled, rather than editing binaries – cat Oct 3 '16 at 11:48
  • @cat: +1 because that is a good-to-remember technicality in general. But in this practical case, I think if you decide to do such a hack-y solution, then the real question is: Does at actually use the string /bin/sh\0 for anything that would break if it ended up also sharing the same string literal, with this particular change? Even without looking at the source, but knowing what at does, I am fairly confident it's likely that the answer is no, it wouldn't actually be a problem. But yes, that is a possibility worth noting. – mtraceur Oct 4 '16 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.