Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:03:58+00:00 2026-05-26T21:03:58+00:00

I have an AWK script which looks like #!/usr/bin/gawk -f BEGIN { print myVar;

  • 0

I have an AWK script which looks like

#!/usr/bin/gawk -f

BEGIN { print myVar; }
{ print; }

which I can run locally in a Unix shell via the command

./myScript.awk -v myVar=value /tmp/inputfile

It correctly prints “value” and then dumps the inputfile.

I set up an apache web server with CGI enabled and created the following myScript.cgi:

#!/usr/bin/gawk -f

BEGIN {
    print "Content-type: text/plain";
    print "";
    print myVar;
}
{ print; }

I can run it by pointing my web browser to

http://localhost/cgi-bin/myScript.cgi?/tmp/inputfile

but how can I pass the “-v myVar=value” bit through the URL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:03:59+00:00Added an answer on May 26, 2026 at 9:03 pm

    You cannot pass a ‘-v’ variable through the CGI interface. The only way to access information is via a number number of environment variables that the CGI interface sets for you. You can access these in awk through the ENVIRON array. You are probably mostly interested in the QUERY_STRING variable, so try this:

    #!/usr/bin/gawk -f
    BEGIN {
        print "Content-type: text/plain"
        print ""
        print ENVIRON["QUERY_STRING"]
    }
    1
    

    When accessed as http://localhost/cgi-bin/myScript.cgi?myVar=foo&otherVar=bar, ENVIRON["QUERY_STRING"] will contain myVar=foo&otherVar=bar. You will have to process this string yourself to extract your variables. For example (untested):

    BEGIN {
        split(ENVIRON["QUERY_STRING"], a, "&")
        for (i in a) {
            if (a[i] ~ /^myVar=/) {
                split(a[i], tmp, "=")
                myVar=tmp[2]
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an awk script that I have defined thus: #!/usr/bin/env awk BEGIN {
Have been trying to write an awk script which processes a log file, but
I have a log file from a web server which looks like this; 1908
I am trying to run an awk script using python, so I can process
I have some awk scripts that use gawk from cygwin. Now I need to
I have found the following command in AWK useful in Vim :'<,'>!awk '{ print
I have an associative array in awk that gets populated like this: chr_count[$3]++ When
I have a text file which I want to filter using awk. The text
I have this snippet I found. svn status | grep '\!' | awk '{print
I have a shell script that constructs an awk program as a string then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.