I do not understand the usage of \ n escape (if you do not understand it, I can discuss it together)
Source: Internet
Author: User
I have some incomprehension about \ n escape usage (if you do not understand it, you can discuss it together)-General Linux technology-Linux technology and application information. The following is a detailed description. The following is a command I entered in shell to check the usage of \ n. There are a few incomprehension points.
1/home/lyn --> $ PS1 = "abc \ ndef $"
2abc
3def $ echo $ PS1
4abc \ ndef $
5abc
6def $ cat> newfile
7abc \ ndef
8 ^ C
9abc
10def $ cat newfile
11abc \ ndef
12abc
13def $ AB = abc \
14> def
15abc
16def $ echo $ AB
17 abcdef
18abc
19def $
First, I understand that double quotation marks place the string abc \ ndef $ in variable ps1. So the following shell prompts that the new value will be read when reading the PS1 variable. However, because \ n in the string is escaped as a line break, the actual prompt is changed:
2abc
3def $
However, I don't understand why \ n is displayed when echo $ PS1 is displayed. Then I tried again, like 6 ~ 11 rows. In the newfile file, I wrote the abc \ ndef string. Then it is displayed in cat newfile. The result is the same as echo $ PS1. It also reads the \ n original, without escaping effect. I went on to experiment again, just like 13 ~ 17 rows.
13def $ AB = abc \ (Press ENTER at this time)
At this time, the \ seems to have escaped the ENTER key, because this row is not over, and it allows me to continue the input, as shown in 14 rows. ENTER def and press ENTER. The command ends normally. However, when the AB variable is displayed, a continuous string abcdef is displayed.
I cannot explain why this problem occurs. It doesn't work. This is why I am here to ask you for advice. Thank you first. I hope someone who understands this question can give me a detailed explanation. Or give me a link. It's hard to think about it.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service