A more concise way of writing what Hennes suggested is
(sleep 5; echo foo) &
Alternatively, if you need more than a few seconds, you could use at
. There are three ways of giving a command to at
:
Pipe it:
$ echo "ls > a.txt" | at now + 1 min
warning: commands will be executed using /bin/sh
job 3 at Thu Apr 4 20:16:00 2013
Save the command you want to run in a text file, and then pass that file to at
:
$ echo "ls > a.txt" > cmd.txt
$ at now + 1 min < cmd.txt
warning: commands will be executed using /bin/sh
job 3 at Thu Apr 4 20:16:00 2013
You can also pass at
commands from STDIN:
$ at now + 1 min
warning: commands will be executed using /bin/sh
at> ls
Then, press CtrlD to exit the at
shell. The ls
command will be run in one minute.
You can give very precise times in the format of [[CC]YY]MMDDhhmm[.ss]
, as in
$ at -t 201412182134.12 < script.sh
This will run the script script.sh
at 21:34 and 12 seconds on the 18th of December 2014. So, in theory, you could use at
to run something five seconds in the future. However, that is kinda like using a tank to swat a fly, and Hennes's suggestion is better.
Why does it not work without the shell? Which error do you get? Are you passing it the full path? Do you know which part parses the
;
? – Hennes – 2013-04-04T17:30:57.430in this way the shell will block 5 seconds and then run the command., the shell to be stalled I do not need that. – Martin – 2013-04-04T17:37:22.387
Then you either need to start it in a script in the background, or in a sub-shell. – Hennes – 2013-04-04T17:39:29.400