[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Idea: jobs(1) -i to print only :%ID:s
From: |
Steffen Nurpmeso |
Subject: |
Re: Idea: jobs(1) -i to print only :%ID:s |
Date: |
Thu, 09 Nov 2023 21:04:28 +0100 |
User-agent: |
s-nail v14.9.24-563-g944131280a |
Greg Wooledge wrote in
<ZU0xybd3KCs6MqdX@wooledge.org>:
|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)
- Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/08
- Re: Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Greg Wooledge, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, alex xmb sw ratchev, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s,
Steffen Nurpmeso <=
- Re: Idea: jobs(1) -i to print only :%ID:s, Andreas Schwab, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, alex xmb sw ratchev, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Greg Wooledge, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, alex xmb sw ratchev, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, alex xmb sw ratchev, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Robert Elz, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Steffen Nurpmeso, 2023/11/09
- Re: Idea: jobs(1) -i to print only :%ID:s, Robert Elz, 2023/11/09