[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
PATCH [1/1]: compressedand - escape single ampersand found in URLs
From: |
Gonzalez, Eric (UMKC-Student) |
Subject: |
PATCH [1/1]: compressedand - escape single ampersand found in URLs |
Date: |
Wed, 22 Apr 2020 18:24:35 +0000 |
I've written a feature I find useful for bash that escapes a single ampersand
if it is surrounded on both sides by any non-blank or non-meta characters. This
logic is toggled by a set option, "compressedand" that can be enabled with `set
[-|+]c` or `set -o compressedand`.
As an example:
$ echo this&echo that
[1] 32324
that
this
[1]+ Done echo this
$ set -c
$ echo this&echo that
this&echo that
Handling of multi-character metas, such as &>, |&, &&, et al, is still parsed
by BASH and their functions remain unaffected.
$ echo this& echo that
[1] 1373
that
this
[1]+ Done echo this
$ echo this &echo that
[1] 1375
that
this
[1]+ Done echo this
$ echo this&&echo that
this
that
$ ps ax&>/tmp/ps&echo
$ ls /tmp/ps\&echo
/tmp/ps&echo
The primary use case for the option is to ease using unquoted URLs as arguments
that have multiple query parameters. Yes, quoting the URL precludes the need
for this feature, but I forget sometimes (okay, too often):
$ set +c
$ echo https://example.com/inputs?v=22&time=now&cp=key
[1] 32335
[2] 32336
https://example.com/inputs?v=22
[1]- Done echo https://example.com/inputs?v=22
[2]+ Done time=now
$ set -c
$ echo https://example.com/inputs?v=22&time=now&cp=key
https://example.com/inputs?v=22&time=now&cp=key
I've attached a patch that was written against bash-4.4 and tested to work
against the most recent DEVEL commit (3235014e5b) as of 04/22. The patch
provides the logic, set option control, and updates to the man and info pages.
I'm still working on getting some tests worked up. I wanted to get this
submitted to get a feel for general likeability and for input on things I need
to do for a proper contribution.
And, for completeness, here are the bash VERSIONs I've tested this on:
GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
GNU bash, version 5.0.16(1)-maint (x86_64-pc-linux-gnu)
I haven't looked up to see what POSIX has to say about this, but I'm fairly
confident that this flies in the face of it. If that's the case and this patch
is dismissed accordingly, I'll accept that. This was a fun exercise anyway. .)
- Eric.
-------------------------------
Fudd's First Law of Opposition:
"If you push something hard enough, it will fall over."
- Firesign Theater
bash-4.4-escape-compressed-ampersand.patch
Description: bash-4.4-escape-compressed-ampersand.patch
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- PATCH [1/1]: compressedand - escape single ampersand found in URLs,
Gonzalez, Eric (UMKC-Student) <=