Hello world/Newline omission: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 23: Line 23:


<lang sh>echo -n "Goodbye World!" # This may not work
<lang sh>echo -n "Goodbye World!" # This may not work
printf "Goodbye World!" # This works. newline is automatically produced</lang>
printf "Goodbye World!" # This works. newline is not automatically produced</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==

Revision as of 01:35, 25 July 2011

Hello world/Newline omission is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Some languages automatically insert a newline after outputting a string, unless measures are taken to prevent its output. The purpose of this task is to output the string "Goodbye, World!" to the terminal, preventing a trailing newline from occuring.

See also

BASIC

<lang basic>10 REM The trailing semicolon prevents a newline 20 PRINT "Goodbye World!";</lang>

Perl

<lang perl>print "Goodbye World!"; # A newline does not occur automatically</lang>

UNIX Shell

The behaviour of echo command is inconsistent across implementations. The -n parameter is not guaranteed to prevent a newline from occuring, so use a printf instead:

<lang sh>echo -n "Goodbye World!" # This may not work printf "Goodbye World!" # This works. newline is not automatically produced</lang>

ZX Spectrum Basic

<lang basic>10 REM The trailing semicolon prevents a newline 20 PRINT "Goodbye World!";</lang>