I have a script
$ cat my.sh
#! /bin/bash -
dirs -l > /tmp/test/dirs_record
jobs > /tmp/test/jobs_record
So when I source ./my.sh
, it will output the dir stack and jobs in the invoking shell.
I have another script schedule.sh
#! /bin/bash -
while : ; do eval "${@}" ; sleep 10 ; done
Running source schedule.sh source ./my.sh
in a bash shell can periodically record the dir stack and jobs in the invoking bash shell.
But I want to run other commands in the same shell, and want source schedule.sh source ./my.sh
to record the up-to-date dir stack and jobs periodically, so I put it in background source schedule.sh source ./my.sh &
, and then since jobs
and dirs
are running in a subshell instead of the invoking shell, any change to the jobs or dir stack to the invoking shell will not be recorded. See Why do `jobs` and `dirs` run in command subsitution, process substitution, pipeline, and background jobs output the same as in original shell?
How can I periodically record the dir stack and jobs of a shell without occupying the shell? For example, can I run a background job directly in the invoking shell?
Thanks.