[Solved] problem assigning value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] problem assigning value
# 1  
Old 11-10-2011
[Solved] problem assigning value

Hi,

This is the script that am trying to execute.
Code:
a= sar 1 5 | grep ^A | awk '{print $5}'
echo $a

i am getting output.
99

i get a blank space for echo $a.
Why is the value not getting assigned to a??

Thanks in Advance.

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 11-10-2011 at 11:16 AM.. Reason: Please use code tags, thank you
# 2  
Old 11-10-2011
Try:
Code:
a=$(sar 1 5 | awk '/^A/{print $5}')

# 3  
Old 11-10-2011
maybe you're missing some quotes...
Code:
a="`sar 1 5 | grep ^A | awk '{print $5}'`"

note the difference between ` (backquote) and " (doublequote).
# 4  
Old 11-10-2011
You did not say what shell you were using...
With ksh try:
Code:
a=$( sar 1 5 | grep ^A | awk '{print $5}')
echo $a

# 5  
Old 11-10-2011
Franklin,

Now i get the output
98
11

"a" did not hold the value.

Aqualung,

The quotes did not help. It says it cannot find the directory.

Vbe,

I am using bash. And yes, I used $, but that did not help either.
# 6  
Old 11-10-2011
Code:
n12:/home/vbe # echo $0
bash
n12:/home/vbe # sar 1 5 |grep ^A
AIX n12 1 6 00C8E5F24C00    11/10/11
Average       31      17       0      52    0.12    59.7
n12:/home/vbe # a=$( sar 1 5 | grep ^A | awk '{print $5}')
n12:/home/vbe # echo $a
00C8E5F24C00 77

AIX bash...
# 7  
Old 11-10-2011
That worked..I guess there was some problem with the syntax :$
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Assigning Shell variable

Hello, Need a small help to execute below script. #!/bin/bash . new.txt for no in 3 4 do echo $((uname_$no)) done new.txt contains uname_1="XXXXXX" uname_2="YYYYY" uname_3="ZZZZZ" ......... (6 Replies)
Discussion started by: prasanna2166
6 Replies

2. Shell Programming and Scripting

[Solved] Assigning a value to a variable name then running a loop on these values

Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer. I have input files containing something like File 1 Apples Apples Apples Apples File 2 Bananas Bananas Bananas Bananas (4 Replies)
Discussion started by: hubleo
4 Replies

3. Shell Programming and Scripting

Problem assigning cmd output to variable then using in IF statement

Hi, I'm using the bourn shell on a Sun Solaris Unix system. I am relatively new to UNIX scripting so please bear with me... I'm having a couple issues: 1) I need to have a variable $FSIZE set with the output of a command each time the script runs. (the command looks for a file and... (8 Replies)
Discussion started by: dqrgk0
8 Replies

4. Shell Programming and Scripting

problem in assigning variable

suppose in my script i have written a1=2 a2=4 read option # I directly want to see the value of a1 or a2 (i:e; 1 or2 )depending upon i/p given like a1 or a2 to option var.so what should i give .Suppose if I give a1 to option then how can I see the value. echo $$option --- doesn't work pls... (3 Replies)
Discussion started by: maitree
3 Replies

5. Shell Programming and Scripting

problem in assigning substr to a variable inside awk

Hi All, I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines. awk '{print substr($0,x,y)}' datafile --- is working fine but awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Discussion started by: loggedin.ksh
3 Replies

6. Shell Programming and Scripting

Problem assigning a counter for particular pattern

Hi, I have a script that compares two files(which are updated dynamically by a daemon) and evaluate results from the comparision. For the first line of comparision from the file1, i will grep some part of the line in file with file1 and set a counter for that particular comparison. So for each... (12 Replies)
Discussion started by: reddybs
12 Replies

7. UNIX for Dummies Questions & Answers

Problem assigning variables to arrays

Hi All, I have a problem assigning variables to script.I have a script in which i have a while loop now i have to assign some values obtained to an array which will be used later in the script.Can anyone help how to do that. At present my scrot looks like: co=0 pco=0 co=`cat /tmp/highcpu... (4 Replies)
Discussion started by: usha rao
4 Replies

8. Shell Programming and Scripting

Problem with assigning output of grep + awk to a variable

Hi All, I am getting the output for the following command when i run it on the unix console. --------------------------- grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3 ---------------------------- But i made it into a script and tried to print the variable, its... (5 Replies)
Discussion started by: meheretoknow
5 Replies

9. Shell Programming and Scripting

problem assigning values to variable

Date of Request: 20080514 10:37 Submitted By: JPCHIANG i want to get the value "JPCHIANG" only in read a file, however, when i do this: name=`"$line"|cut -d " " -f8` it display all the line and append 'not found' at the end of the statement the $line is actually a variable in a... (2 Replies)
Discussion started by: finalight
2 Replies

10. Shell Programming and Scripting

Problem in assigning values to variables

Hi, I have some problem in assigning values to variables: This is what Iam literally doing: i=0 input=test temp$i = $input In the sense, I try to assign the value in the variable input (ie., test) to another variable temp0 (since i is assigned 0, temp$i is temp0). Seems simple, but I get... (3 Replies)
Discussion started by: mohanprabu
3 Replies
Login or Register to Ask a Question