On XSI-conformant systems, if the first operand is -n , it shall be treated as a string, not an option. The following character sequences shall be recognized on XSI-conformant systems within any of the arguments:. And so there really isn't any general way to know how to write a newline with echo , except that you can generally rely on just doing echo to do so. A bash shell typically does not conform to the specification, and handles the -n and other options, but even that is uncertain.
You can do:. And not even that is necessary if bash has been built with the build-time option Make the echo builtin expand backslash-escaped characters by default, without requiring the -e option. See Bash Builtins , for a description of the escape sequences that echo recognizes.
The printf utility was added to provide functionality that has historically been provided by echo. However, due to irreconcilable differences in the various versions of echo extant, the version has few special features, leaving those to this new printf utility, which is based on one in the Ninth Edition system. See Why is printf better than echo? Actually, no In all versions of bash I've used, you may simply insert a literal newline into a string either interactively or in a script, provided that the string is sufficiently quoted.
People have already answered adequately, but I refuse to accept a world where echo accepts any option other than -n. If you are trying to echo text containing exclamation marks! Thanks to:. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Learn more. How to add new lines when using echo Ask Question. Asked 6 years, 5 months ago. This signals not to add a new line. It may look something like this: 1 2 3 4 5. If you want all your input to print on the same line for some reason, you can always use the first example.
This is extremely useful for building a CSV file, for example. We will consider 2 aspects of printing a new line in batch script. Also, by using EnableDelayedExpansion you can achieve the blank line. You may need any one of them in different situations. When you are running a series of utilities in a single batch file, you may need to echo a blank line between utility execution to have a clear view of the command prompt.
Learn how echo new line in batch file works. Note: The main code is between the REM statement. The two spaces are mandatory. Output: Hello World.
0コメント