On 6/29/21 4:21 PM, L A Walsh wrote: > I hope a basic question isn't too offtopic.
Well, if you don't think this is a bug in bash, but something you need help figuring out, maybe you'd prefer to use the "help-bash" list? > 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" This is obviously broken, because {$1:+expand} isn't how bash works. Try swapping the "{" and the "$"... > } > > 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! What's wrong with the obvious v=$(jobs | wc -l) > 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; } > > > > > -- Eli Schwartz Arch Linux Bug Wrangler and Trusted User
OpenPGP_signature
Description: OpenPGP digital signature