Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > alt.comp.lang.shell.unix.bourne-bash > #268

Re: Escaping grep

Date 2021-04-17 17:58 +0200
From bodiccea <bodiccea@gmail.com>
Newsgroups alt.comp.lang.shell.unix.bourne-bash
Subject Re: Escaping grep
Message-ID <20210417175837.3c83dcab@lorien> (permalink)
References <s0ujo2$1i0$1@dont-email.me> <20210417153619.6d991200@lorien>
Organization Guest of ProXad - France

Show all headers | View raw


On Sat, 17 Apr 2021 15:36:19 +0200, bodiccea <bodiccea@gmail.com> wrote:
> You have 2 solutions:
> 1) use quotes instead of double quotes: '^\\usep', so that bash does
> not change anything.
> 2) using double quotes, force bash to preserve 2 backslash with the
> string "^\\\\usep"

As a general rule, when you are unsure about "real" strings sent to a
program (like grep in your case), you can always test them with printf,
I do it sometimes with complicated patterns.

Examples:
# your initial string
$ printf "%s\n" "^\\usep"
^\usep                           <-- passed to grep, incorrect

# with quotes
br@lorien:~/.claws-mail$ printf "%s\n" "^\\\\usep"
^\\usep                          <-- passed to grep, correct

# with double quotes
br@lorien:~/.claws-mail$ printf "%s\n" '^\\usep'
^\\usep                          <-- passed to grep, correct

bodi.

Back to alt.comp.lang.shell.unix.bourne-bash | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Escaping grep "Michael F. Stemper" <mstemper@gmail.com> - 2021-02-21 15:35 -0600
  Re: Escaping grep Lewis <g.kreme@kreme.dont-email.me> - 2021-02-22 06:36 +0000
  Re: Escaping grep bodiccea <bodiccea@gmail.com> - 2021-04-17 15:36 +0200
    Re: Escaping grep bodiccea <bodiccea@gmail.com> - 2021-04-17 17:58 +0200
      Re: Escaping grep "Michael F. Stemper" <mstemper@gmail.com> - 2021-04-17 11:08 -0500
        Re: Escaping grep bodiccea <bodiccea@gmail.com> - 2021-04-17 19:21 +0200
    Re: Escaping grep "Michael F. Stemper" <mstemper@gmail.com> - 2021-04-17 11:06 -0500

csiph-web