The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
storing result of a command in variable eltinator Shell Programming and Scripting 1 04-17-2008 08:09 PM
Storing a variable? hoover90 Shell Programming and Scripting 4 01-26-2008 09:39 PM
Storing the output into a variable ravi raj kumar UNIX for Dummies Questions & Answers 7 12-11-2006 09:14 AM
storing output of awk in variable mab_arif16 Shell Programming and Scripting 3 05-07-2006 06:15 PM
Storing values in variable matrixmadhan Shell Programming and Scripting 1 04-01-2005 01:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-11-2008
nookie nookie is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
storing a command in a variable

how would i go about storing this command in a variable

echo "$LINE" | awk -F"|" '{print $1"|"$2"|"$3"}'

i have tried FOO = ${command up there} but receive the error FOO: not found

aswell as a couple of other attempt but no luck
  #2 (permalink)  
Old 10-11-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by nookie View Post
how would i go about storing this command in a variable

echo "$LINE" | awk -F"|" '{print $1"|"$2"|"$3"}'

i have tried FOO = ${command up there} but receive the error FOO: not found

aswell as a couple of other attempt but no luck
Code:
FOO=$(echo "$LINE" | awk -F"|" '{print $1"|"$2"|"$3"}')
  #3 (permalink)  
Old 10-11-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 708
Hi.

There is a difference between storing the text of a command and storing the results of a command in a variable; vino provided the latter. In any case, you need to omit the spaces around the "=" sign. If you have a space, then the Bourne family shells will assume you wish to run a command, such as FOO. That usually produces an error message, as you have seen.

It is good that you provided the evidence for your problem. However, data and commands are far easier to read when you place them inside CODE blocks as vino did. To do that, select the text and press the # just above the editing window.

Best wishes ... cheers, drl
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0