![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Storing count(*) into unix variable | mervinboyz | Shell Programming and Scripting | 1 | 03-26-2008 08:14 PM |
| Storing a variable? | hoover90 | Shell Programming and Scripting | 4 | 01-26-2008 06:39 PM |
| Using 'defaults read' and storing the output in a variable | davewg | Shell Programming and Scripting | 0 | 11-14-2007 05:04 AM |
| storing output of awk in variable | mab_arif16 | Shell Programming and Scripting | 3 | 05-07-2006 03:15 PM |
| Storing values in variable | matrixmadhan | Shell Programming and Scripting | 1 | 03-31-2005 10:56 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Storing the output into a variable
Hi unix gurus,
I am trying to store the result of a command into a variable. But it is not getting stored. x='hello' y=echo $x | wc -c but it is giving the output as 0(zero) Pls help me its very urgent |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
x='hello' y=$(echo $x | wc -c) |
|
#3
|
|||
|
|||
|
x='hello' y=$(echo $x | wc -c) echo $y z='expr $y + 1 ' echo $z Its printing expr $y + 1 instead of 7. any idea pls. cheers Ravi Raj kumar |
|
#4
|
|||
|
|||
|
can you try back quotes instead
Code:
z=`expr $y + 1` |
|
#5
|
|||
|
|||
|
Thank u so much boss.Its working now fine. Thanks a lot. cheers Ravi raj kumar |
|
#6
|
||||
|
||||
|
You need to understand the difference between
y=$(echo $x | wc -c) and z='expr $y + 1 ' In y=$(echo $x | wc -c), the output of the command echo $x | wc -c is stored into y. It is known as command substitution. You can do a command substitution in two ways. Either use $(...) or `...` In z='expr $y + 1', the string expr $y + 1 is stored in z without any literal expansion. |
|
#7
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |