LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 04-13-2009, 12:09 AM   #1
GahseyFan
LQ Newbie
 
Registered: May 2007
Posts: 2

Rep: Reputation: 0
echoing whitespace from a command substitution


I have run into a problem in a script where I want to preserve whitespace in a statement similar to:

echo $(ls -l)

The newline characters appear to be dropped. echo's -e option did not change the behavior, can anyone give insight into how bash interprets the above line? Thanks!
 
Old 04-13-2009, 01:27 AM   #2
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: Mandriva, RHEL, Mageia, SuSE
Posts: 132

Rep: Reputation: 17
Hi,

all you need is paired quotation marks
Code:
echo "$(ls -l)"
 
Old 05-16-2009, 05:58 AM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 231Reputation: 231Reputation: 231
Make that paired double quotation marks: using single quotation marks will echo the command string itself -- as you will find out if you try it.


Quote:
Originally Posted by GahseyFan View Post
. . . can anyone give insight into how bash interprets the above line? Thanks!
Not easily, I usually take a pragmatic approach & add the quotation marks when white space, & especially new lines, are getting lost.

It's a long & daunting document, but the bash man page is a starting point. Good luck.
 
  


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
passing a veriable in a command substitution dwj79 Programming 4 04-02-2009 03:46 AM
find command and file names with whitespace sir_woland Linux - General 8 10-04-2007 08:10 PM
Bash Command Substitution dakensta Programming 5 11-30-2006 04:10 PM
Command substitution and sed daYz Linux - General 9 11-04-2006 02:15 AM
command substitution: ^ rhxk Linux - General 2 04-06-2006 10:51 AM


All times are GMT -5. The time now is 10:40 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration