[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to escape shell string in gawk?
From: |
Peng Yu |
Subject: |
Re: How to escape shell string in gawk? |
Date: |
Sat, 16 May 2020 21:16:02 -0500 |
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