1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

escapes getting into program

Discussion in 'Support' started by fpefpe, May 4, 2009.

  1. fpefpe

    Joined:
    Oct 18, 2008
    Messages:
    238
    Likes Received:
    1
    Greetings --

    I am trying to tun gawk and getting a error --

    the awk cmd is

    awk `{ print $1}`

    I used the ` char since the jpsoft doc note that the contents are pass
    to the program as-is, but gawk generate an error message that ` is
    invalid -- how is the ` getting into the gawk program
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    fpefpe wrote:
    | Greetings --
    |
    | I am trying to tun gawk and getting a error --
    |
    | the awk cmd is
    |
    | awk `{ print $1}`
    |
    | I used the ` char since the jpsoft doc note that the contents are
    | pass
    | to the program as-is, but gawk generate an error message that ` is
    | invalid -- how is the ` getting into the gawk program

    Simple - the whole argument, include the ` character, is passed on. Unless
    the command line includes one of the special characters that have
    syntactical meaning to TCC you do not need any form of quoting.
    --
    HTH, Steve
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,178
    Likes Received:
    11
    I don't know what you're trying to accomplish. But this works for me:

    awk -- "{ print $1 }"

    awk -- "BEGIN { print \"Hello world\" }"

    -Scott


    fpefpe <> wrote on 05/04/2009 07:45:31 PM:


     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,788
    Likes Received:
    29
    On Mon, 04 May 2009 18:45:59 -0500, fpefpe <> wrote:

    |the awk cmd is
    |
    |awk `{ print $1}`
    |
    |I used the ` char since the jpsoft doc note that the contents are pass
    |to the program as-is, but gawk generate an error message that ` is
    |invalid -- how is the ` getting into the gawk program

    I can't explain it but I doubt they're being passed to awk (unless awk is
    somehow special). TCC just doesn't do that. For example:

    v:\> u:\EchoArgs.exe `{ print $1 }`
    u:\EchoArgs.exe
    {
    print
    $1
    }

    Have you perhaps used SETDOS to disable the back-quote?
    --
    - Vince
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    vefatica wrote:
    | I can't explain it but I doubt they're being passed to awk (unless
    | awk is somehow special). TCC just doesn't do that. For example:
    |
    | v:\> u:\EchoArgs.exe `{ print $1 }`
    | u:\EchoArgs.exe
    | {
    | print
    | $1
    | }

    That's not my observation. My 15-year old ANSI C program (text mode, of
    course) argparse.exe reports with equivalent command line (identical command
    tail):

    Command tail: '{ print $1 }'
    0 "C:\UTIL\ARGPARSE.EXE"
    1 "'{"
    2 "print"
    3 "$1"
    4 "}'"

    Note that the backticks are part of the command tail and of the 1st and 4th
    argument. All this with SETDOS reporting EXPANSION=0, i.e., nothing
    disabled.
    --
    Steve
     
  6. Howard Goldstein

    Joined:
    Jun 1, 2008
    Messages:
    111
    Likes Received:
    1
    Steve Fabian wrote:

    But those are forward ticks, not backticks!

    --
    Howard
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,788
    Likes Received:
    29
    On Mon, 04 May 2009 20:15:55 -0500, Steve Fábián <> wrote:

    |That's not my observation. My 15-year old ANSI C program (text mode, of
    |course) argparse.exe reports with equivalent command line (identical command
    |tail):
    |
    |Command tail: '{ print $1 }'
    |0 "C:\UTIL\ARGPARSE.EXE"
    |1 "'{"
    |2 "print"
    |3 "$1"
    |4 "}'"
    |
    |Note that the backticks are part of the command tail and of the 1st and 4th
    |argument. All this with SETDOS reporting EXPANSION=0, i.e., nothing
    |disabled.

    How can that be? 4NT/TCC never passed on back-quotes (to my knowledge). Here's
    another test, using my 5-minute old test.exe:

    g:\projects\test\release> type ..\test.cpp
    #include <windows.h>
    #include <stdio.h>

    INT wmain ( INT argc, WCHAR **argv )
    {
    WCHAR *pszCommandLine = GetCommandLineW();
    wprintf(L"%s\n", pszCommandLine);
    return 0;
    }
    g:\projects\test\release> test.exe `{ foo }`
    test.exe { foo }
    --
    - Vince
     
  8. fpefpe

    Joined:
    Oct 18, 2008
    Messages:
    238
    Likes Received:
    1
    Greetings --

    No, I don't think that I turned of quoting with setdos.
    I was trying to run gawk command using the back tick ` prevent the
    command line from being process. I kept getting errors, so I wrote a simple C
    program to echo the contents of the argv array passed into the program. In
    addition, I also called the win/api "GetComamndLine" to get the complete command
    line

    If I am reading the doc correctly, the ` character when used to start and end an
    argument, should be striped way and the text between them passed to the program
    in the same way the ' work for unix shell.
    From my simple program, that does not seem to be the case -- Did I miss read
    the doc?

    Thanks

    Frank Esposito

    Sample program output -->

    Cmd line {args this is a `test`}
    Args Count: 5

    Argument(0) is {args}
    Argument(1) is {this}
    Argument(2) is {is}
    Argument(3) is {a}
    Argument(4) is {`test`}
     
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    I don't know what's going on on your system, but on mine the backquotes definitely are stripped before a command is executed. What do you see when you do e.g.

    Code:
    echo `foo`
    What does VER /R report?
     
  10. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,788
    Likes Received:
    29
    On Fri, 15 May 2009 17:18:01 -0500, fpefpe <> wrote:

    |Sample program output -->
    |
    |Cmd line {args this is a `test`}
    |Args Count: 5
    |
    |Argument(0) is {args}
    |Argument(1) is {this}
    |Argument(2) is {is}
    |Argument(3) is {a}
    |Argument(4) is {`test`}

    That's contrary to what I see (and contrary to the way 4NT/TCC has always
    worked):

    v:\> args this is a `test`
    args
    this
    is
    a
    test

    Are you talking about the backtick which is on the key just to the left of the
    "1" key?
    --
    - Vince
     
  11. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    I use gawk, but I assume that it's the same for awk.
    First of all, use double quotes around your inline script:
    awk "{ print $1}"
    this works for me. The confusion starts when you need to use double quotes also inside the script. You need to use 3 double quotes to escape one single double quote in a gawk inline script, so:

    awk "{ print """dollar1="""$1}"
    this also works for me. Happy (g)awking

    Years ago I read a post which stated that backtick processing is broken in awk for Windows. Now, I don't know what that really means, if awk actually makes up the backticks or what, but anyway I found the magic trick with the 3 double quotes and I'm happy.
     

Share This Page