bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to escape shell string in gawk?


From: david kerns
Subject: Re: How to escape shell string in gawk?
Date: Sat, 16 May 2020 16:59:44 -0700

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
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]