The UNIX and Linux Forums  

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
Iteration through the results from a unix command deviprasad83 Shell Programming and Scripting 4 06-12-2008 05:04 AM
joining command results, and substitution ncatdesigner Shell Programming and Scripting 6 04-17-2008 12:37 PM
Setting the Results of a Command to a Variable stky13 UNIX for Dummies Questions & Answers 1 02-29-2008 03:00 PM
My ps -ef|grep command results are chopped off bsp18974 UNIX for Dummies Questions & Answers 1 08-14-2007 11:35 AM
How to output the results of the AT command - properly! SpanishPassion UNIX for Dummies Questions & Answers 4 12-04-2005 10:27 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-18-2008
alirezan alirezan is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 22
Results of command execution into array

Hi

Can anybody tell me how can I dump the results of execution of a command into array form? For example, I want to execute:

Quote:
fdisk -l | grep 83 | grep Linux
and put each part of the result in an array element:

Quote:
root /home/alireza Revolution 1# fdisk -l | grep 83 | grep Linux
/dev/sda1 1 15000 120487468+ 83 Linux
/dev/sda2 15001 20837 46885702+ 83 Linux
/dev/sda5 20838 21969 9092789+ 83 Linux
/dev/sda6 21970 23101 9092789+ 83 Linux
/dev/sda7 23102 27000 31318717 83 Linux
/dev/sdb1 1 2361 18964701 83 Linux
/dev/sdb3 2362 4722 18964732+ 83 Linux
/dev/sdb5 4723 7033 18563076 83 Linux
/dev/sdb6 7034 9344 18563076 83 Linux
/dev/sdb7 9345 11655 18563076 83 Linux
/dev/sdb8 11656 13966 18563076 83 Linux
/dev/sdb9 13967 16277 18563076 83 Linux
/dev/sdb10 16278 18588 18563076 83 Linux
/dev/sdb11 18589 20899 18563076 83 Linux
/dev/sdb12 20900 23210 18563076 83 Linux
/dev/sdb13 23211 25521 18563076 83 Linux
/dev/sdb14 25522 27832 18563076 83 Linux
/dev/sdb15 27833 29000 9381928+ 83 Linux
/dev/sdc1 1 8941 71818551 83 Linux
Thanks
  #2 (permalink)  
Old 08-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
If your system supports process substitution:

Code:
IFS='\
' read -d'^Y' -a array < <(fdisk -l | grep 83 | grep Linux)
'^Y' is just a randomly chosen character that should not occur in the input data (entered using Ctrl-V Ctrl-Y).

Last edited by Annihilannic; 08-19-2008 at 01:00 AM.. Reason: process substitution, not named pipes
  #3 (permalink)  
Old 08-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
If it doesn't support process substitution. Try this:

Code:
fdisk -l | grep 83 | grep Linux > /tmp/tempfile
IFS='\
' read -d'^Y' -a array < /tmp/tempfile

Last edited by Annihilannic; 08-19-2008 at 01:00 AM.. Reason: process substitution, not named pipes
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 08:04 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