[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parameter expansion with extended pattern make system hang
From: |
Chet Ramey |
Subject: |
Re: Parameter expansion with extended pattern make system hang |
Date: |
Tue, 6 Sep 2022 11:55:52 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 |
On 9/4/22 10:48 PM, Hyunho Cho wrote:
Bash Version: 5.1
Patch Level: 16
Release Status: release
##############################################################
#### "gcc --help" is already a short string, but the system hangs.
A short string? It's 90K on my system.
( without using extended pattern, there is no such problem )
bash$ help=$( gcc --help )
bash$ echo "${help//+([$' \t\n'])/ }"
So what you're doing is taking a 90K string, and for each character in the
string, trying to match it against successively shorter substrings,
starting at the end to preserve the required `leftmost longest' match
semantics. It's worse because you can't calculate the pattern length here,
so you can't bound the search at all. Nor are you building a regular
expression and trying to execute it against the strings; this is just a
simple pattern matcher.
It's hard to think of a less efficient way of doing whatever it is you're
trying to do.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Re: Parameter expansion with extended pattern make system hang, Chet Ramey, 2022/09/06