[Top][All Lists]

[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 (Windows/20100228)

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

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

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"

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?

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]