Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Getting command from ARGV[1] doesn't work in AWK
This simple script stored in test.awk:

#!/usr/bin/awk -f
{
print | "cat > /tmp/output"
}

works as expected when fed data, e.g.

$ ls|test.awk

Likewise, when modified slightly:

#!/usr/bin/awk -f
BEGIN { cmd = "cat > /tmp/output" }
{
print | cmd
}

it still works, dumping the output of 'ls' into the specified file.

This also works:

#!/usr/bin/awk -f
{
print | cmd
}

when fed the command:

$ ls|./test.awk -v 'cmd=cat > /tmp/output'

But(!), this script doesn't work:

#!/usr/bin/awk -f
BEGIN { cmd = ARGV[1]; ARGV[1] = "" }
{
print | cmd
}

when fed the command:

$ ls|./test.awk 'cat > /tmp/output'

It silently does nothing at all. There is no file /tmp/output and there
is no file in the local directory called 'cat > /tmp/output', nor one
called 'cat', for that matter.

Change the first line of the script to:

#!/usr/local/bin/gawk -f

and the last case works.

AWK version is:

localhost ~/tmp bash2.05$ /usr/bin/awk -V
awk version 981019

as distributed with Mac OS X 10.3.

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Hart
04-11-05 08:56 PM


Re: Getting command from ARGV[1] doesn't work in AWK
In article <HemdnYGh7eDeUczfRVn-2Q@gwi.net>, Jim Hart  <jhart@bates.edu> wro
te:
...
>It silently does nothing at all. There is no file /tmp/output and there
>is no file in the local directory called 'cat > /tmp/output', nor one
>called 'cat', for that matter.

OK - sounds like a buggy AWK to me.

>Change the first line of the script to:
>
>#!/usr/local/bin/gawk -f
>
>and the last case works.

Thank you for saving us all the trouble of testing it under gawk.
Basically, you won't get much support here for problems specific to (buggy)
vendor-supplied AWKs.

>AWK version is:
>
>localhost ~/tmp bash2.05$ /usr/bin/awk -V
>awk version 981019
>
>as distributed with Mac OS X 10.3.

Yup - sounds like a buggy AWK to me.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
04-11-05 08:56 PM


Re: Getting command from ARGV[1] doesn't work in AWK
In article <HemdnYGh7eDeUczfRVn-2Q@gwi.net>, Jim Hart  <jhart@bates.edu> wrote:
>But(!), this script doesn't work:
>
>#!/usr/bin/awk -f
>BEGIN { cmd = ARGV[1]; ARGV[1] = "" }
>{
>         print | cmd
>}
>
>when fed the command:
>
>$ ls|./test.awk 'cat > /tmp/output'

Change this:

BEGIN { cmd = ARGV[1]; ARGV[1] = "" }

to:

BEGIN { cmd = ARGV[1]; ARGC = 1 }


John
--
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/

Report this thread to moderator Post Follow-up to this message
Old Post
John DuBois
04-11-05 08:56 PM


Re: Getting command from ARGV[1] doesn't work in AWK
In article <pan.2005.04.06.11.41.50.846508@my.sig>,
E. Rosten <look@my.sig> wrote:

% quits silently. mawk and gawk seem to treat '' as if it does not exist as
% a command line argument at all (which seems like the wrong behaviour to
% me, since it looks more like a non-existent file as opposed to lack of a
% filename (==stdin)).

This is the behaviour defined by posix. The one true awk did not work that
way historically, but it may have been changed lately.
--

Patrick TJ McPhee
North York  Canada
ptjm@interlog.com

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick TJ McPhee
04-11-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:06 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.