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 > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to get pid of a process and have to store the pid in a variable samudha UNIX for Dummies Questions & Answers 7 08-05-2008 03:24 AM
How to store the sql query's output in a variable venkatesh_sasi Shell Programming and Scripting 4 01-18-2008 01:03 AM
store the first line of a file in a variable dineshr85 Shell Programming and Scripting 0 12-06-2007 04:41 AM
To store the output in a variable Sudhakar333 Shell Programming and Scripting 2 07-10-2007 08:45 AM
store awk results in a variable forever_49ers Shell Programming and Scripting 1 09-19-2006 10:51 PM

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 08-17-2007
smartbuddy smartbuddy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 6
How to Store command O/P to a variable...

Hi all..

I got a problem..
Its easy to redirect o/p to a file.. But Is it possible to redirect the O/P to a variable?

For example:

I've a command in my script:

Code:
string1=cut -d ':' -f2 file.txt
When I do:

Code:
echo $string1
The value is empty... Pls suggest me how to store the value of the cut command in string1 variable..
  #2 (permalink)  
Old 08-17-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
Code:
#!/bin/ksh
string1=$(cut -d ':' -f2 file.txt)
I am not sure if you want to store the entire contents to a single vairable
  #3 (permalink)  
Old 08-17-2007
smartbuddy smartbuddy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 6
Quote:
Originally Posted by lorcan View Post
Code:
#!/bin/ksh
string1=$(cut -d ':' -f2 file.txt)
I am not sure if you want to store the entire contents to a single vairable
I'm getting the following error while execution:

syntax error at line 5: '(' unexpected
  #4 (permalink)  
Old 08-17-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
what is the shell and the OS version
  #5 (permalink)  
Old 08-24-2007
smartbuddy smartbuddy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 6
Sun OS 5.8 and bash

Quote:
Originally Posted by lorcan View Post
what is the shell and the OS version
My Unix Version is Sun OS 5.8 and working in bash.

Thanks.
  #6 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by smartbuddy View Post
My Unix Version is Sun OS 5.8 and working in bash.

Thanks.

Did you try what i suggested above.That will work for you.

Thanks
Namish
  #7 (permalink)  
Old 08-22-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Thumbs up

Quote:
Originally Posted by smartbuddy View Post
Hi all..

I got a problem..
Its easy to redirect o/p to a file.. But Is it possible to redirect the O/P to a variable?

For example:

I've a command in my script:

Code:
string1=cut -d ':' -f2 file.txt
When I do:

Code:
echo $string1
The value is empty... Pls suggest me how to store the value of the cut command in string1 variable..
You can do something like this--

#!/bin/ksh

str1=`cut -d":" -f2 file.txt
echo $str1

This will work i hope.

Thanks
Namish
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 09:01 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