How to call a variable in awk again ?

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Programming How to call a variable in awk again ?
# 1  
How to call a variable in awk again ?

Hi again and thanks to R.Singh.

One more question here.

The code works in awk. (or GAWK)

awk 'BEGIN{print "Enter your Name: ";getline name < "-";print RS "Input entered by user is: "name}'

How to display the variable name again ?

The awk script is running automaticly to the end.

I have tied :
echo  $name
                     awk ' {print "name"} '

Seems that the variable is gone from the memory.

DURING a program execution they stay. However.

But how to hold the program in interpreted modus ?

awk is interpreted i think . anyway it ends the script automaticly in the CMD terminal from Linux.

Any suggestions or ideas about that ?


Last edited by Corona688; 05-17-2017 at 06:12 PM..
# 2  
Hello Zabo,

Not sure why there is a necessity for using awk? You could use shell's built-in command called read to take Input from user, following is an example for same too.
cat script.ksh 
echo "enter a variable please:"
read variable
echo "I am printing variable here......."
echo $variable

So while running the above script following output will come.
enter a variable please:
R. Singh
I am printing variable here.......
R. Singh

I hope this helps you, kindly do let me know if you have any queries on same.

R. Singh
# 3  
code tags for code, please.

awk is awk, shell is shell. If you don't output the value in awk, it won't get put out.

VAR=$(awk '{ ... }' )

For interactive programs, you should be printing prompts and such to > "/dev/stderr", so they won't end up in VAR.

Or you could write the whole program in awk, or at least do a large amount of processing in awk, so there's less need for transfer.
# 4  
down vote
You cannot grab the output of an awk system() call, you can only get the exit status. Use the getline/pipe or getline/variable/pipe constructs

awk '{
    cmd = "your_command " $1
    while (cmd | getline line) {
}' file

Moderator's Comments:
Mod Comment please use code tags

Ethan Stark

Last edited by jim mcnamara; 06-13-2017 at 10:32 AM.. Reason: code tags
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #238
Difficulty: Easy
Steve Jobs was the first to build a theoretical model for communication using packet switching.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to call variable inside a function globally?

Hi Gurus, Is there a way to call a variable inside a function anywhere within the script? Thanks. BR, Ernesto (2 Replies)
Discussion started by: ernesto
2 Replies

2. Shell Programming and Scripting

Dereferencing variable inside egrep call

Hi guys I am trying to dereference a variable inside 'egrep -v ' command and getting a 'egrep: syntax error' : $ echo $exclude_list ts584d hf584db for i in `echo $exclude_list`; do egrep -v ${i} my_file done egrep: syntax error egrep: syntax error The syntax of the loop is correct.... (1 Reply)
Discussion started by: aoussenko
1 Replies

3. Shell Programming and Scripting

Call a awk script with variable and input filename

HI, MY question is a very simple one: if i want to call an awk script with the input file name and also pass a variable value , then how to do it. #>awk -f my_script.awk -v variable=value my_inputfile.txt I can't do it like this. throws error: awk: my_script.awk:18:... (0 Replies)
Discussion started by: Onkar Banerjee
0 Replies

4. Shell Programming and Scripting

Passing awk variable in perl -e call

Hi. I am on a Solaris box and have an awk script which calls perl via the command line: timeTester="'"`perl -e 'use Time::Local;my $time = timelocal(10,10,10,10,10,2011 );print $time'`"'" But I want to pass awk variables into this call. These are the example awk variables: secondField = 10... (0 Replies)
Discussion started by: pedro6994
0 Replies

5. Shell Programming and Scripting

How to call arguments with variable in a script??

Hello, I was wondering if it were possible to call arguments passed to a script using a variable. For example: sh yes no good bad x=$# while do echo (last argument, then second last etc until first argument) let x=($x-1) done should print out bad good no (4 Replies)
Discussion started by: VanK
4 Replies

6. Shell Programming and Scripting

Variable names within array call

I am trying to write a piece of code that will call a value from an array. There are multiple arrays that I need to call data from. Only one array needs to be used based on the step within the program. The arrays have the names "cue_0", "cue_1", and so on. I can't figure out how to call a value... (2 Replies)
Discussion started by: vockleya
2 Replies

7. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies

8. Programming

Setting environment variable using JNI call

I have function declaration in Java and same function definition written in C programming language.. A JNI call from Java is made to a fuction...Function would set the environment variable { putenv(cEnvString1);} using C-built -in function ..and later return the encrypted string... putenv is... (6 Replies)
Discussion started by: shafi2all
6 Replies

9. Shell Programming and Scripting

Enviornment Variable in B shell (I call it nested variable)

#!/bin/sh APP_ROOT_MODE1=/opt/app1.0 APP_ROOT_MODE2=/opt/app2.0 APP_ROOT=${APP_ROOT_${APP_MODE}} # enviornment variable APP_MODE will be exported in the terminal where # we run the applciation, its value is string - MODE1 or MODE2 # My intension is: # when export APP_MODE=MODE1... (4 Replies)
Discussion started by: princelinux
4 Replies

10. UNIX for Dummies Questions & Answers

does this variable call work--Korn

I am new to the UNIX environment, but not to programming. My intention is to create a 2D array and print it. Since the Korn Shell does not support that kind of variable, the following is my solution right now. I have created a group of variables as follows: table00 table01 table02 table10... (2 Replies)
Discussion started by: morkfard
2 Replies