Greg Wooledge wrote in
<[email protected]>:
|On Thu, Nov 09, 2023 at 08:09:23PM +0100, Steffen Nurpmeso wrote:
|> j() {
|> local j= a=${AWK:-awk}
|> [ $# -gt 0 ] && j='&& $2 !~ /(^| )('$(echo "$@" | tr ' ' '|')')( \
|> |$)/'
|> j=$(jobs -l | $a -F '[][]' '/^[[]/'"$j"'{print "%" $2}{next}')
|> echo $j
|>}
|
|Classic code injection vulnerability.
Well this is for me on my command line. ash(1) and busybox ash(1)
do not even support jobs -l in a function (yet). (Where??)
|What are we even parsing? Start with the input:
|
|unicorn:~$ sleep 5 &
|[1] 849028
|unicorn:~$ jobs -l
|[1]+ 849028 Running sleep 5 &
|
|OK, so you wanted to strip the "1" from "[1]" and turn that into "%1",
|yes? That shouldn't be terribly hard in pure bash.
|
| re='^\[([0-9]+)\]'
| jobspecs=()
| while IFS= read -r line; do
| if [[ $line =~ $re ]]; then
This is indeed a nice approach. I have now spend over an hour
stupid me, and have no more time to extend this to filter out the
unwanted jobs, but i copy your thing over to my ~/.profile for
a future full implementation! (Likely selectively after testing
which shells actually do support this syntax, ie ksh and such.)
| jobspecs+=( "%${BASH_REMATCH[1]}" )
| fi
| done < <(jobs -l)
|
|Wrap that in a function with local declarations, etc.
Thanks!
Ciao,
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)