Can you launch an awk script this way?

Can you launch an awk script this way?

Post by Robin W. Winsle » Thu, 04 Nov 1993 23:49:15



I've got a user trying with start his awk scripts with the line

  #!/bin/awk -f

so they can be self contained, i. e., if "myawkscript" is the name
of an awk script and "myfile" is the file he wants to process, he wants
to write

  myawkscript myfile

instead of

  awk -f myawkscript myawkfile

Is this doable?  I know perl allows you to encapsulate a script in this
manner, but does awk also have this capability?

Thanks,

Robin
--

Shell Oil Company, Information Center                !{uupsi}!shell!rww
Houston, TX                                              (713) 245-2694

 
 
 

Can you launch an awk script this way?

Post by Glen Jerome Browni » Sat, 06 Nov 1993 04:58:11



: I've got a user trying with start his awk scripts with the line

:   #!/bin/awk -f

: so they can be self contained, i. e., if "myawkscript" is the name
: of an awk script and "myfile" is the file he wants to process, he wants
: to write

:   myawkscript myfile

: instead of

:   awk -f myawkscript myawkfile

: Is this doable?  I know perl allows you to encapsulate a script in this
: manner, but does awk also have this capability?

Hi,

I don't know if he can do it the way he's trying to, but he could try
something like this:

       alias myawkscript 'awk -f myawkscript'

This is a simple alias, but I think it should work.  
If it doesn't, try changing it to this:

       alias myawkscript 'awk -f myawkscript '

The only change is the addition of the space just before the closing single quote.

With one of these aliases, he should be able to type the following:

      myawkscript myfile

Hope it helps.

Glen.

 
 
 

Can you launch an awk script this way?

Post by Dan P » Sat, 06 Nov 1993 07:39:43



Quote:>I've got a user trying with start his awk scripts with the line

>  #!/bin/awk -f

>so they can be self contained, i. e., if "myawkscript" is the name
>of an awk script and "myfile" is the file he wants to process, he wants
>to write

>  myawkscript myfile

>instead of

>  awk -f myawkscript myawkfile

>Is this doable?  I know perl allows you to encapsulate a script in this
>manner, but does awk also have this capability?

This is not a feature of perl or awk, it's built into the execve() system
call, so any script interpreter can be invoked in this way. From the man
page of execve:

     An interpreter file begins with a line of the form "#! interpreter". When
     an interpreter file is execved, the system execve's the specified
     interpreter, giving it the name of the originally exec'd file as an
     argument and shifting over the rest of the original arguments.

Dan
--
Dan Pop
CERN, L3 Experiment

Mail:  CERN - PPE, Bat. 21 1-023, CH-1211 Geneve 23, Switzerland

 
 
 

Can you launch an awk script this way?

Post by J. Sei » Sat, 06 Nov 1993 07:48:26


'#!/anypath/anyprog extra options' in a file myfile is the same
as "/anypath/anyprog 'extra options' myfile" from the command
line with any parameters tacked on after that.  grep is another
"unusual" shell interpreter that you will see occasionally.

Joe Seigh

 
 
 

Can you launch an awk script this way?

Post by damer.. » Sat, 06 Nov 1993 09:04:14



: I've got a user trying with start his awk scripts with the line

:   #!/bin/awk -f

: so they can be self contained, i. e., if "myawkscript" is the name
: of an awk script and "myfile" is the file he wants to process, he wants
: to write

:   myawkscript myfile

: instead of

:   awk -f myawkscript myawkfile

: Is this doable?  I know perl allows you to encapsulate a script in this
: manner, but does awk also have this capability?

: Thanks,

: Robin
: --

: Shell Oil Company, Information Center                !{uupsi}!shell!rww
: Houston, TX                                              (713) 245-2694

Yes,  I do it all the time.  One caveat - nothing,  not even a space,
must follow the -f.

--
Dan Mercer                                            Applications + Plus

======================================================================
About a year ago I told the following joke which got a strong positive
reaction from only 1 in 5 (all males my age - 40+) and shrugs from the
rest.  I wonder if it is more relevant now?

"What does Mogadishu mean in Somali?"  Answer - "Saigon"

 
 
 

Can you launch an awk script this way?

Post by Guy Harr » Sat, 06 Nov 1993 10:01:27


Quote:>I've got a user trying with start his awk scripts with the line

>  #!/bin/awk -f

        ...

Quote:>Is this doable?

It depends on the flavor of UNIX you're using.

Many of them do have support in the "exec" family of calls for the "#!"
feature; not all do, however.

 
 
 

Can you launch an awk script this way?

Post by Rich Holla » Mon, 08 Nov 1993 08:54:00



Quote:>       alias myawkscript 'awk -f myawkscript'
>       alias myawkscript 'awk -f myawkscript '
[...]
>With one of these aliases, he should be able to type the following:
>      myawkscript myfile

Nope, try: alias myawkscript 'awk -f myawkscript \!*' to feed it the
rest of the command line...

--

723 Allison Ave, #8, Manhattan, KS  66502-3273
(913) 776-5789

 
 
 

Can you launch an awk script this way?

Post by Ulyanov Anato » Tue, 09 Nov 1993 05:13:57



>'#!/anypath/anyprog extra options' in a file myfile is the same
>as "/anypath/anyprog 'extra options' myfile" from the command
>line with any parameters tacked on after that.  grep is another
>"unusual" shell interpreter that you will see occasionally.
>Joe Seigh

The related question. Does anybody have an idea how I can to overcome
the restrictions on the path in the first line with #!. I can run a
script that starts with:

#!/bin/awk or !/usr/bin/awk;

but when I want to use gawk in my local directory:

#!/my_disk/my_lab/anatoly/bin/sun4/gawk -f,

 I have a message "Command not found".

I use tcsh 6.04.00 (Cornell) 93/07/03 (sun4) options 8b,nls,dl,al and
SPARCstation 10 with SunOS Release 4.1.3

Anatoly
--
-------------------------------------------------------------------------------
:-( Dr. Anatoly V. Ulyanov                                                  (-:
:-( Department of Molecular Cellular and Development Biology                (-:
:-( University of Colorado at Boulder Campus Box 347, Boulder,Co 80309-0347 (-:

 
 
 

Can you launch an awk script this way?

Post by Vladimir Ivanov » Tue, 09 Nov 1993 13:42:17


anatoly> The related question. Does anybody have an idea how I can to overcome
anatoly> the restrictions on the path in the first line with #!. I can run a
anatoly> script that starts with:

anatoly> #!/bin/awk or !/usr/bin/awk;

anatoly> but when I want to use gawk in my local directory:

anatoly> #!/my_disk/my_lab/anatoly/bin/sun4/gawk -f,

anatoly> I have a message "Command not found".

Try at the begining of your file:

#!/bin/sh
#

if 0;
# The lines above are due to the kernel's built in limit on the
# length of the interpreter string.

... perl code deleted ...

Naturally, replace the /usr/local/exe/perl with the appropriate absolute
pathname of the interpreter you wish to use.

-- Vladimir
--
Vladimir G. Ivanovic                            SunPro
(415) 336-2315                                  MTV12-33

{decwrl,hplabs,ucbvax}!sun!Eng!vladimir         Mountain View, CA 94043-1100
                         Disclaimer: I speak for myself.

 
 
 

Can you launch an awk script this way?

Post by Rudi Vankemm » Tue, 09 Nov 1993 22:28:08


Hi,


: >'#!/anypath/anyprog extra options' in a file myfile is the same

 [ ..... deleted ......]

: The related question. Does anybody have an idea how I can to overcome
: the restrictions on the path in the first line with #!. I can run a
: script that starts with:

: #!/bin/awk or !/usr/bin/awk;

: but when I want to use gawk in my local directory:

: #!/my_disk/my_lab/anatoly/bin/sun4/gawk -f,

:  I have a message "Command not found".

: I use tcsh 6.04.00 (Cornell) 93/07/03 (sun4) options 8b,nls,dl,al and
: SPARCstation 10 with SunOS Release 4.1.3

Hmmmmm, I ran across the same problem in a script. It seems that
the path specification length is limited to 30 characters (as far as I
remember) for which #!/bin/awk works and #!/my_disk/..... isn't.
I had it solved by including the executable directory in my path variable
and then simply calling the program on the first line.
E.g. in your case put /my_disk/my_lab/anatoly/bin/sun4 in your path
and change the script file first line into:
 e.g. #!gawk -f

I hope this works,
-------------------------------------------------------------------------------
  Rudi Vankemmel                      | These are my opinions, not those of
  IMEC vzw. - ASP division            | my employer, so don't take them away
  Process and Device Modelling group  |________________________________________
  Kapeldreef 75                            phone: (32)-(0)16/28 13 37
  3001 Leuven                              fax:   (32)-(0)16/28 12 14

-------------------------------------------------------------------------------

 
 
 

Can you launch an awk script this way?

Post by Casper H.S. D » Tue, 09 Nov 1993 23:15:39



>Hmmmmm, I ran across the same problem in a script. It seems that
>the path specification length is limited to 30 characters (as far as I
>remember) for which #!/bin/awk works and #!/my_disk/..... isn't.
>I had it solved by including the executable directory in my path variable
>and then simply calling the program on the first line.
>E.g. in your case put /my_disk/my_lab/anatoly/bin/sun4 in your path
>and change the script file first line into:
> e.g. #!gawk -f

That doesn't work.  The kernel knows nothing of your $PATH variable
and will not sue it.

You can use the following script to determine how much characters
execve will pick up:

#!/bin/echo 12345678901234567890123456789012345678901234567890123456789012345678901234567890

One some systems (BSDish, such as SunOS 4.x) give output like this:
12345678901234567890 ./echo

when run as ./echo.

The usual limitation is sizeof(struct exec) or sizeof(struct a.out).

In Solaris 2.x, there is no apparent limitation:
12345678901234567890123456789012345678901234567890123456789012345678901234567890 ./echo

Casper

 
 
 

Can you launch an awk script this way?

Post by Danny R. Faug » Tue, 09 Nov 1993 23:19:51




>I had it solved by including the executable directory in my path variable
>and then simply calling the program on the first line.
>E.g. in your case put /my_disk/my_lab/anatoly/bin/sun4 in your path
>and change the script file first line into:
> e.g. #!gawk -f

You must use an absolute path in hash-bang scripts, so I don't see how
this could work.

When I had a problem with scripts lately, it was suggested that I use
"indir".  indir's purpose is to increase the security of setuid
scripts, but it looks like as a side effect, it allows lots more
gymnastics than you're allowed to use in the first line of a hash-bang
script.
--
Danny Faught -- Convex rookie -- MPP OS Test Development
"Everything is deeply intertwingled."  (Ted Nelson, _Computer Lib_)

 
 
 

Can you launch an awk script this way?

Post by Jeremy Mathe » Wed, 10 Nov 1993 01:48:01



Quote:>>E.g. in your case put /my_disk/my_lab/anatoly/bin/sun4 in your path
>>and change the script file first line into:
>> e.g. #!gawk -f

>That doesn't work.  The kernel knows nothing of your $PATH variable
>and will not sue it.

              ^^^
Well, I certainly hope no legal action will be taken.  Hate to have to
get the lawyers into this!

But, more to the point, he claims that it did work, on his system, so
I'm not sure we can convince him otherwise.  It certainly is not
supposed to work, of course.

Quote:>You can use the following script to determine how much characters
>execve will pick up:

>#!/bin/echo 12345678901234567890123456789012345678901234567890123456789012345678901234567890

>One some systems (BSDish, such as SunOS 4.x) give output like this:
>12345678901234567890 ./echo

>when run as ./echo.

Assuming the above text is put into a file called echo, and run via ./echo,
then it did the right thing in appending ./echo to the end of the command line.
This is the same as appending the filename to the usual the first line
of the script shown below, to form the command line "/bin/awk -f foo":

#!/bin/awk -f
...

************************************************************************
You blidderin' dimwit, Olivia!
How can you leadin' a heart after I's makin' Lightner Double?


          hundreds, if not thousands, of dollars, every time he posts -
************************************************************************
rwvpf wpnrrj ibf ijrfer

 
 
 

Can you launch an awk script this way?

Post by Casper H.S. D » Wed, 10 Nov 1993 02:25:28



>But, more to the point, he claims that it did work, on his system, so
>I'm not sure we can convince him otherwise.  It certainly is not
>supposed to work, of course.

It works in exactly one case: the executable you want to execute
is in the current working directory.

Quote:>>One some systems (BSDish, such as SunOS 4.x) give output like this:
>>12345678901234567890 ./echo

>>when run as ./echo.
>Assuming the above text is put into a file called echo, and run via ./echo,
>then it did the right thing in appending ./echo to the end of the command line.
>This is the same as appending the filename to the usual the first line
>of the script shown below, to form the command line "/bin/awk -f foo":

I wasn't complaining about the ./echo, I was execpting that.  It's
the truncated command line that is wrong.

(Solaris 2.x still prints ./echo, but it also print the entire line in
the file.)

Casper

 
 
 

1. How (many ways) can a shell script read stdin?

If you want a (bourne) script to read from standard input and when
data is received, run some command on that input, is there a "normal"
way to do that?

E.g., I want to write a script that will grep on standard input; I
don't want to run grep separately on each line, so what to do with the
results of "read"?

I wound up with:

    SCRATCH=/tmp/scratchpage.$$
    while read LINE
            do
            echo "$LINE" >> $SCRATCH
    done

And then grepping the file $SCRATCH.  Is that the normal way to do
this?  What if you didn't want it to have to wait for all data to be
received?  Can stdin be redirected to a pipe?

levin

2. Modem control lines

3. KNode won't launch from kicker panel (but launches fine from CL)

4. changing my HD

5. launch script from a CD

6. X driving me nuts

7. Need help launching Tk Scripts

8. mid size ATX case?

9. help: a bash script to launch x-win and then do someting in x-win

10. Launching a script upon connecting the cable

11. Launch a script with sendmail

12. Launching a script after appearance of a file

13. startup scripts that launch a program over NFS mounts