Bash میں نیو لائن پرنٹ کریں۔

تعارف

In Bash, a نئی لائن refers to the end of a line of text and the beginning of a new one. When a command is executed in Bash, the output is often displayed on the terminal with each line of text ending in a new line. The new line character is represented by a special escape sequence, n, which tells the terminal to move the cursor to the beginning of the next line.

Printing a new line in Bash is important because it helps to format the output in a way that is easy to read and understand. For example, if you are printing the results of a command that produces a lot of output, using new lines can make it easier to parse the information. Additionally, new lines can be used to visually separate different sections of output, making it easier to locate specific information.

In this article, we’ll take a a look at several different ways to print a new line, including using the echo کے ساتھ حکم -e اختیار، printf command, and the escape sequence n.

Two Ways to Print a New Line in Bash

Here are several different ways to print a new line in Bash. In this section we’ll take a look at two most common.

یہاں یاد آتی ہے کے ساتھ حکم "-to" آپشن

۔ echo command is used to display a message or output on the Bash. It is often used to print a string of text, but it can also be used to print the value of a variable or the output of a command.

۔ echo command has a number of options that allow you to customize its behavior. The one we are interested in is the -e option, which allows you to use escape sequences to include special characters in the output.

That specific option enables us to use the n special character to print a new line in Bash:

echo -e "This is the first linenThis is the second line"

یہ ہمیں دے گا:

This is the first line
This is the second line

یہاں پرنف کمانڈ

In Bash, the printf command is used to display a message or output in the terminal. It is similar to the echo command, but it is generally more powerful and flexible, and it is often preferred over echo for formatting and printing output in Bash scripts.

پسند echo, printf can be used to print a string of text, the value of a variable, or the output of a command. However, printf آپ کو بھی اجازت دیتا ہے specify a format string, which allows you to control the appearance of the output in more detail.

Therefore, there is no need to use any special options/flags (like -e), just write the stirng format between two quotation marks:

printf "This is the first linenThis is the second line"

As expected, this will yield us with:

This is the first line
This is the second line

نوٹ: In all of these examples, the n escape sequence is used to represent a new line. The echo اور printf commands are used to print the text to the terminal, and the -e کے لئے اختیار echo allows it to interpret the escape sequences.

نتیجہ

In conclusion, writing a new line in Bash is an important task that allows you to format the output of your scripts and commands in a way that is easy to read and understand. In this article, we covered two most common ways to write a new line in Bash – using the echo کے ساتھ حکم -e اختیار، اور printf کمانڈر

ٹائم اسٹیمپ:

سے زیادہ Stackabuse