I hope a basic question isn't too offtopic.
Say I have some number of jobs running:

 jobs|wc -l
3
---
in a function (have tried shopt -s/-u lastpipe; neither way worked)
njobs() {
jobs |wc -l
}
 njobs
3

Would like to pass a varname to njobs to store the answer in, like:
njobs() {
jobs|wc -l
#magic puts val in $v
printf {$1:+-v $1} "%s\n" "$v"
}

So I can run:

 njobs n
echo "$n"
3

-----------
How can I put the output into '$v'
*without* using a temporary file?

This seems so basic, yet its eluding me.
Could someone throw me a clue-stick?
Tnx!

p.s. - a trivial util func producing jobs:

resleep() { alias my="declare " int="my -i "
int n=${1:-3} t=${2:-99}; echo "$n jobs @ ${t}s:"
while ((0 < n--)); do sleep "$t" & done; }





Reply via email to