[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to escape shell string in gawk?
From: |
Wolfgang Laun |
Subject: |
Re: How to escape shell string in gawk? |
Date: |
Sun, 17 May 2020 07:57:28 +0200 |
How to escape a quote and a space (and anything else the shell should not
see):
$ gawk -v tmpfile='"'$tmpdir/a\ b.txt'"' ... # individual quoting
or
$ gawk -v tmpfile='"'$tmpdir/'a b.txt"' ... # combine quote, space and
others
$ man bash
for a complete reference about quoting.
-W
On Sun, 17 May 2020 at 04:16, Peng Yu <address@hidden> wrote:
> What about both a double quote (") and whitespace in a string?
>
> On 5/16/20, david kerns <address@hidden> wrote:
> > white space in filenames is a nasty thing usually reserved for Windows
> > users...
> >
> > tmpdir=$(mktemp -d)
> > echo a > "$tmpdir/a b.txt"
> > awk -v tmpfile="$tmpdir/a b.txt" -e 'BEGIN {cmd=sprintf("cat
> > \"%s\"",tmpfile); cmd|getline x;print x}'
> >
> >
> >
> > On Sat, May 16, 2020 at 4:09 PM Peng Yu <address@hidden> wrote:
> >
> >> Hi,
> >>
> >> I can not escape the shell string below. Is there a way to do so?
> Thanks.
> >>
> >> $ tmpdir=$(mktemp -d)
> >> $ echo a > "$tmpdir/a b.txt"
> >> $ awk -v tmpfile="$tmpdir/a b.txt" -e 'BEGIN { "cat " tmpfile |
> >> getline x; print x }'
> >> cat: /tmp/mktemp/tmp.XjMDBFsh9R/a: No such file or directory
> >> cat: b.txt: No such file or directory
> >> $ awk -v tmpfile=$(builtin printf %q "$tmpdir/a b.txt") -e 'BEGIN {
> >> "cat " tmpfile | getline x; print x }'
> >> awk: cmd. line:1: b.txt
> >> awk: cmd. line:1: ^ syntax error
> >>
> >> --
> >> Regards,
> >> Peng
> >>
> >>
> >
>
>
> --
> Regards,
> Peng
>
>