LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   echoing whitespace from a command substitution (http://www.linuxquestions.org/questions/linux-general-1/echoing-whitespace-from-a-command-substitution-718700/)

GahseyFan 04-13-2009 12:09 AM

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!

Vit77 04-13-2009 01:27 AM

Hi,

all you need is paired quotation marks
Code:

echo "$(ls -l)"

archtoad6 05-16-2009 05:58 AM

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 (Post 3506927)
. . . 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.


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