Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My script contains something like this:

ifc=$(ifconfig)

With this, the ifc variable contains the output of the command ifconfig but without newlines. So, when I print it with echo $ifc I get only one line.

How can I include the newlines of subcommands?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

The correct way to print is

echo "$ifc"
share|improve this answer
    
oh! that easy... thanks :-) –  Ethan Leroy Oct 1 '10 at 9:12
    
Works! Why, though? –  Alison Apr 8 '13 at 11:22
    
see Word Splitting in bash(1), you need quoting to preserve the spaces, tabs, or newlines. –  livibetter Apr 8 '13 at 14:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.