"Embedding" an awk script in bash 
Author Message
 "Embedding" an awk script in bash

  I had a little bunch of scripts written in both bash and gawk to
configure some things
on my linux box. The shell scripts called the gawk scripts. Everything
worked fine.

  Trying to make them more neat, I putted the awk code inside the shell
scrips. Now it doesn't work, trying to do funny things:

# this is (part of) my shell script
# PORT is asigned a value before
/usr/bin/gawk port="$PORT" '
  BEGIN {
    getline mypid < "/dev/pid"
    tmpfile="/tmp/configure" mypid
  }
  # lines, lines, lines
  ' /etc/myconfigfile

### Output:
gawk: cmd. line:2: fatal: illegal name `
  BEGIN {
    getline mypid < "/dev/pid"
    tmpfile' in variable asignment

  Why does gawk try to use the whole two-and-a-half lines as variable
name?

--
Ral Pedroche



Sun, 29 Sep 2002 03:00:00 GMT  
 "Embedding" an awk script in bash

Quote:

>   I had a little bunch of scripts written in both bash and gawk to
> configure some things
> on my linux box. The shell scripts called the gawk scripts. Everything
> worked fine.

>   Trying to make them more neat, I putted the awk code inside the
shell
> scrips. Now it doesn't work, trying to do funny things:

It's arguable whether this makes it more neat. =)

Quote:
> # this is (part of) my shell script
> # PORT is asigned a value before
> /usr/bin/gawk port=3D"$PORT" '
>   BEGIN {
>     getline mypid < "/dev/pid"
>     tmpfile=3D"/tmp/configure" mypid
>   }
>   # lines, lines, lines
>   ' /etc/myconfigfile

> ### Output:
> gawk: cmd. line:2: fatal: illegal name `
>   BEGIN {
>     getline mypid < "/dev/pid"
>     tmpfile' in variable asignment

>   Why does gawk try to use the whole two-and-a-half lines as variable
> name?

Dunno. But if you change it to: awk -v port="...
things should work.

/Peter
--
-= Spam safe(?) e-mail address: pez at pezius.com =-

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 29 Sep 2002 03:00:00 GMT  
 "Embedding" an awk script in bash


% /usr/bin/gawk port="$PORT" '

gawk is treating
 port="$PORT"
as the program, and the program as an input file.

You can prefix the assignment with -v, or put it after the script.
--

Patrick TJ McPhee
East York  Canada



Mon, 30 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to do PHP "require()" or TCL "source" in bash script

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. (patch for Bash) Bash with embedded Python

4. "&" and Awk

5. awk "search and replace"

6. Looking for "pretty-printer"/reformatter for AWK

7. sources from "The AWK Programming Language"

8. "script" vs. "expect script"

9. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

10. Browse "hotfield" embed question

11. "Big" embedded systems

12. ANNOUNCE:transportable-state,safe,postscript-like,"agent",embedded,language

 

 
Powered by phpBB® Forum Software