LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-08-2014, 01:09 PM   #1
mia_tech
Member
 
Registered: Dec 2007
Location: FL, USA
Distribution: CentOS 5.3, Ubuntu 9.04
Posts: 245

Rep: Reputation: 16
how to declare an array from command substitution in bash


hi everyone, how could I store the output of command substitution into an array
lets say I have the following output
Code:
var=$(du -h | sort -hr | grep ./ | head -3)
but this stores everything into $var, so when I output the content of $var, it shows everything in one line. How could I do stdout so it shows
size file
size file
size file
 
Old 03-08-2014, 01:18 PM   #2
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 594

Rep: Reputation: 141Reputation: 141
Use double quotes around $var
Code:
bash-4.2$ echo "$var"
2.4G	./Downloads
1.3G	./Documents/Documents
1.3G	./Documents
 
1 members found this post helpful.
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - command substitution kopert Programming 8 09-18-2012 04:13 AM
mkdir in bash script - command substitution casperdaghost Linux - Newbie 3 06-26-2010 05:10 AM
bash: case and command substitution--what gives? David the H. Programming 9 09-03-2009 02:08 AM
BASH command substitution that starts with a pipe | Kristofer Programming 4 02-27-2007 05:52 PM
Bash Command Substitution dakensta Programming 5 11-30-2006 03:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration