![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| how could i make a program mixed with many "|", "<" and ">" | strugglingman | High Level Programming | 2 | 04-29-2006 08:11 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 04:15 AM |
| "Global" profiles? | amheck | UNIX for Dummies Questions & Answers | 6 | 12-04-2005 08:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
AWK -> getting "global" vars
Hello,
presently, I'm calling nawk from my main script and have nawk defined in one file. So I call nawk like this nawk -f file input This file defines how to separate mails in /var/mail/$user and show 1 at a time. However, I would also like to do other actions (delete message, forward message, etc), but I don't want to do separately. I mean to create a new "nawk" file just for forwarding... . The thing I would like is to pass a variable into this nawk file so I can decide what to do (print, forward, delete) and have it in one place. But the problem is I have no clue how to pass info and get it in nawk file. I hope there is someone with a clue. Thx. Peto |
|
||||
|
Is it possible to get a value from NAWK?
so I can print every message and let user choose which mail to delete and after that I would get which mail he chose and after that I would call nawk again with action=delete mail=value... |
|
|||||
|
Quote:
Code:
#!/bin/ksh
eval $(nawk -v action='choose' -f file.awk input.txt)
echo "ChosenRecord->[${chosenRecord}]"
Code:
BEGIN {
# if no action is specified on the command line - default to "print"
if (action == "")
action="print"
}
function doChoose()
{
# here we're doing the "choosing" - Once a record is chosen...
printf("chosenRec=%d\n", numberOfChosenRecord);
}
{
if ( action == "choose" )
doChose
if ( action == "print" )
doPrint
if ( action == "forward" )
doForwarding
if ( action == "whatever" )
doWhatever
}
|
|
||||
|
When I write
eval $( nawk -f forward.awk /var/mail/$USER ) it wants more input so I have to end it with double ^D . Also I'm not sure if I understand it correctly. What does eval do in this example? Does it return value which was returned from nawk? so I can get it by using $? . How nawk return a value? : return 55 ? Is it possible to use "global variables" that I can modify also in nawk and have it changed in parent script. |
![]() |
| Bookmarks |
| Tags |
| bash, bash eval, eval |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|