Sponsored Content
Top Forums Shell Programming and Scripting Note: environment variables within awk Post 303030789 by MadeInGermany on Friday 15th of February 2019 01:18:35 PM
Old 02-15-2019
The DEBUG=$DEBUG ensures that DEBUG exists in the environment for the awk.
But it's pure overhead if it was already in the shell's environment.
You can achieve the same with an exported variable (exported = placed in the shell's environment)
Code:
export DEBUG
test "$1" = "-v" && DEBUG=1 || DEBUG=0
mysql -e 'SHOW SLAVE STATUS \G' | mysql_slave_check

Because DEBUG is in the shell's environment, all the run commands inherit it.

The use of ENVIRON[ ] in an awk script is interesting. Thanks for sharing!
It is not used often. Reason: when awk is run from the shell there is easy passing of variables.
The Posix style:
Code:
test "$1" = "-v" && DEBUG=1 || DEBUG=0
mysql -e 'SHOW SLAVE STATUS \G' | awk -v DEBUG=$DEBUG -f mysql_slave_check

Or the (bit dirty) Unix awk style
Code:
test "$1" = "-v" && DEBUG=1 || DEBUG=0
mysql -e 'SHOW SLAVE STATUS \G' | awk -f mysql_slave_check DEBUG=$DEBUG

Either invocation sets the DEBUG variable in awk, so there is no need for pulling it from ENVIRON[ ]
These 2 Users Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

what is the use of Environment variables

what is the actual use of environment variables. I know only PS1, LOGNAME, PS2 variables what are the other variables & what is there use (2 Replies)
Discussion started by: indianguru
2 Replies

2. Programming

environment variables

Hi! How-to get the environment variables in GNU. getenv() only fetches the ones that you can find under export (not the ones under declare)... best regars .David (2 Replies)
Discussion started by: Esaia
2 Replies

3. UNIX for Dummies Questions & Answers

environment variables

Hi Folks, Is it possible somehow to unset all the environment variables which have been defined before in UNIX (Solaris). Thanks, Slava (3 Replies)
Discussion started by: spavlov
3 Replies

4. Programming

environment variables

hi, I want to create a new EV(Environment Variable) through a c program and I done this thing through setenv() method. But the newly created EV is not permanent, i.e. when I exit from the program the EV also no longer lives. But I want to make it a permanent EV for the current user. Actually I... (6 Replies)
Discussion started by: sumsin
6 Replies

5. Shell Programming and Scripting

using environment variables

say i define an environment variable in a particular script (upgrade.sh). my script is upgarde.sh and it calls another script try.sh. will this environment variable be accessible to try.sh also. if not how to I make environment variables global so that they can be used by any script. (2 Replies)
Discussion started by: lassimanji
2 Replies

6. UNIX for Dummies Questions & Answers

Environment variables

why are all environment variables represented in a fixed format regardless of the shell you use? like $HOME $PATH etc (6 Replies)
Discussion started by: sravani
6 Replies

7. Shell Programming and Scripting

get xml note by awk

Hi all, I have a file contain 100 lines xml. Would like to get the note value of special attribute. Could anyone help? input: <a>1</a><b>2</b><c>3</c><d>4</d><e>5</e><f>64</f> <a>1</a><b>2</b><c>33</c><d>4</d><e>56</e><f>63</f> <a>1</a><b>2</b><c>66</c><d>4</d><e>58</e><f>62</f>... (3 Replies)
Discussion started by: mimilaw
3 Replies

8. HP-UX

Environment Variables

Hi Experts, Need your help in understanding the commands to setup the environment variables in hp-ux. Beleive need to use either set,setenv or export. I am confused between above three options, when to use which option? On command line, I have tried both set and setenv but couldn't... (1 Reply)
Discussion started by: sai_2507
1 Replies

9. Homework & Coursework Questions

Environment Variables

1. The problem statement: What is the mesg value set for your environment? If it is on, how would you turn off your current session? How would you set it permanently? 3. The attempts at a solution : Read Unix The textbook. 3rd chapter has many things like environment variables and... (5 Replies)
Discussion started by: mahinkhan22
5 Replies

10. HP-UX

Environment Variables

Hi All, I need to understand following three environment variables and their usages in HP Unix. _M_ARENA_OPTS _M_CACHE_OPTS PTHREAD_SCOPE_SYSTEM How does these environment variables influence multi threaded applciation and how do we decide the value of these variables? Is there... (0 Replies)
Discussion started by: angshuman
0 Replies
English(3pm)						 Perl Programmers Reference Guide					      English(3pm)

NAME
English - use nice English (or awk) names for ugly punctuation variables SYNOPSIS
use English; use English qw( -no_match_vars ) ; # Avoids regex performance penalty # in perl 5.16 and earlier ... if ($ERRNO =~ /denied/) { ... } DESCRIPTION
This module provides aliases for the built-in variables whose names no one seems to like to read. Variables with side-effects which get triggered just by accessing them (like $0) will still be affected. For those variables that have an awk version, both long and short English alternatives are provided. For example, the $/ variable can be referred to either $RS or $INPUT_RECORD_SEPARATOR if you are using the English module. See perlvar for a complete list of these. PERFORMANCE
NOTE: This was fixed in perl 5.20. Mentioning these three variables no longer makes a speed difference. This section still applies if your code is to run on perl 5.18 or earlier. This module can provoke sizeable inefficiencies for regular expressions, due to unfortunate implementation details. If performance matters in your application and you don't need $PREMATCH, $MATCH, or $POSTMATCH, try doing use English qw( -no_match_vars ) ; . It is especially important to do this in modules to avoid penalizing all applications which use them. perl v5.18.2 2014-01-06 English(3pm)
All times are GMT -4. The time now is 09:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy