| Deutsch English Français Italiano |
|
<v7n9s1$2p39$1@nnrp.usenet.blueworldhosting.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!panix!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED!not-for-mail
From: "Arti F. Idiot" <addr@is.invalid>
Newsgroups: comp.unix.shell
Subject: Re: bash aesthetics question: special characters in reg exp in [[ ...
=~~ ... ]]
Date: Mon, 22 Jul 2024 22:00:00 -0600
Organization: Anarchists of America
Message-ID: <v7n9s1$2p39$1@nnrp.usenet.blueworldhosting.com>
References: <v7mknf$3plab$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Jul 2024 04:00:01 -0000 (UTC)
Injection-Info: nnrp.usenet.blueworldhosting.com;
logging-data="91241"; mail-complaints-to="usenet@blueworldhosting.com"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AG6JUDB7H/wlPbpD0fegYDlQyLM= sha256:HL5RS1a0sntLcqKi2ZB7q3vPBtmBn3a9P8U1B49sOR0=
sha1:RExEUNYfC6BNX5mC6R0SJYpV7DI= sha256:0saFfpBABkfXvPN4e2ksUvN0Rl3pg/KReeVm/naPBs0=
In-Reply-To: <v7mknf$3plab$1@news.xmission.com>
Content-Language: en-US
Bytes: 2326
Lines: 30
On 7/22/24 3:59 PM, Kenny McCormack wrote:
> Note: this is just a question of aesthetics. Functionally, it all works as
> expected.
>
> Sample bash code:
>
> f="$(fortune)" # Get some multi-line output into "f"
> # Look for foo followed by bar on the same line
> [[ "$f" =~ foo[^$'\n']*bar ]] && echo "foo bar"
>
> The point is you need the "anything other than a newline" or else it might
> match foo on one line and bar on a later line. The above is the only way I
> could figure out to express a newline in the particular flavor of reg exps
> used by the =~ operator.
>
> The problem is that if the above is in a function, when you list out the
> function with "type funName", the \n has already been digested and
> converted to a hard newline. This makes the listing look strange. I'd
> rather see "\n".
>
> Is there any way to get this?
>
Not sure this really addresses your 'type funcName' query but maybe
somewhat better output from 'type funcName' ? :
...
regex=$(printf 'foo[^$\n]*bar')
[[ "$f" =~ $regex ]] && echo "foo bar"
Kind of wish the regex string could be bracketed by "/" as in awk.