Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]

Liste des GroupesRevenir à cu shell 
Sujet : Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]
De : addr (at) *nospam* is.invalid (Arti F. Idiot)
Groupes : comp.unix.shell
Date : 23. Jul 2024, 05:00:00
Autres entêtes
Organisation : Anarchists of America
Message-ID : <v7n9s1$2p39$1@nnrp.usenet.blueworldhosting.com>
References : 1
User-Agent : Mozilla Thunderbird
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.

Date Sujet#  Auteur
22 Jul 24 * bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]19Kenny McCormack
23 Jul 24 +* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]9Kaz Kylheku
23 Jul 24 i`* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]8Janis Papanagnou
23 Jul 24 i +* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]6Kenny McCormack
23 Jul 24 i i`* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]5Janis Papanagnou
23 Jul 24 i i `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]4Kenny McCormack
23 Jul 24 i i  `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]3Janis Papanagnou
23 Jul 24 i i   `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]2Kenny McCormack
24 Jul 24 i i    `- Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]1Janis Papanagnou
23 Jul 24 i `- Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]1Kaz Kylheku
23 Jul 24 `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]9Arti F. Idiot
23 Jul 24  `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]8Kenny McCormack
23 Jul 24   `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]7Kaz Kylheku
24 Jul 24    +* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]5Ben Bacarisse
24 Jul 24    i`* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]4Kaz Kylheku
24 Jul 24    i `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]3Ben Bacarisse
24 Jul 24    i  `* Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]2Kaz Kylheku
24 Jul 24    i   `- Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]1Ben Bacarisse
24 Jul 24    `- Re: bash aesthetics question: special characters in reg exp in [[ ... =~~ ... ]]1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal