Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 04-12-2009, 11:09 PM   #1
LQ Newbie
Registered: May 2007
Posts: 4

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, 12:27 AM   #2
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17

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

Rep: Reputation: 233Reputation: 233Reputation: 233
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.

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.



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 02:46 AM
find command and file names with whitespace sir_woland Linux - General 8 10-04-2007 07:10 PM
Bash Command Substitution dakensta Programming 5 11-30-2006 03:10 PM
Command substitution and sed daYz Linux - General 9 11-04-2006 01:15 AM
command substitution: ^ rhxk Linux - General 2 04-06-2006 09:51 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:55 PM.

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