Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-19-2005, 10:15 PM
|
#1
|
LQ Newbie
Registered: Nov 2005
Location: Australia
Posts: 18
Rep:
|
newline problem
How do I print:
with echo?
The following doesn't work like the one above:
echo hello\nworld
echo hello\0nworld
echo "hello\nworld"
The \n doesn't get interpreted as a newline, but why?
What's the right command?
regards
|
|
|
11-19-2005, 10:18 PM
|
#2
|
Member
Registered: May 2004
Posts: 552
Rep:
|
Code:
echo -en "hello\nworld\n"
|
|
|
11-19-2005, 11:09 PM
|
#3
|
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Rep:
|
randyding -
harrylmh's suggestion about "echo -en" is exactly correct ... if your question is about the shell's "echo".
I'm wondering if maybe your question is actually about php's "echo" - perhaps you want to see newlines in an HTML web page generated by PHP.
If you're not seeing the newline in a web browser, then the solution is to add an HTML "<br>" tag
EXAMPLE:
<?php
echo "Hello<br>world\n";
?>
'Hope that helps .. PSM
PS:
If you were asking about the shell echo in the first place, harrylmh's answer should already have you squared away. In that case, please accept my humble apologies ;-)
|
|
|
11-20-2005, 05:54 AM
|
#4
|
LQ Newbie
Registered: Nov 2005
Location: Australia
Posts: 18
Original Poster
Rep:
|
Yes! thanks, randyding, your code worked.
PS: yes, I was referring to shell
|
|
|
11-21-2005, 05:04 AM
|
#5
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
-ethat's an annoying bash thing.
echo '\n' works in ksh and sh
|
|
|
All times are GMT -5. The time now is 03:42 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|