bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

simple prob?


From: L A Walsh
Subject: simple prob?
Date: Tue, 29 Jun 2021 13:21:44 -0700
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

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

[Prev in Thread] Current Thread [Next in Thread]