复制,粘贴和回显到txt文件维护换行符

时间:2016-03-30 13:59:34

标签: bash shell echo

我在命令行上做了一个教程。在其中一个练习中,我需要将Dynamic Script Loadingecho复制粘贴到新文件中。 问题是新文件中没有新行,事实上,当我cat文件时,每一节都附加到前一页。

我是否必须在每行末尾手动添加"\n"? 我希望有更好的方法(因为如果有1000行会怎么样?)

更新 这是我到目前为止所做的事情

首先我从sonnet复制十四行诗。然后我将它粘贴到终端中以编写此命令:

~$ echo "FRom faireſt creatures we deſire increaſe, That thereby beauties Roſe might neuer die, But as the riper ſhould by time deceaſe, His tender heire might beare his memory: But thou contracted to thine owne bright eyes, Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell, Making a famine where aboundance lies, Thy ſelfe thy foe,to thy ſweet ſelfe too cruell: Thou that art now the worlds freſh ornament, And only herauld to the gaudy ſpring, Within thine owne bud burieſt thy content, And tender chorle makſt waſt in niggarding:    Pitty the world,or elſe this glutton be,    To eate the worlds due,by the graue and thee." > sonnet.txt

最后我查看了内容:

cat sonnet.txt

但我明白了:

FRom faireſt creatures we deſire increaſe, That thereby beauties Roſe might neuer die, But as the riper ſhould by time deceaſe, His tender heire might beare his memory: But thou contracted to thine owne bright eyes, Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell, Making a famine where aboundance lies, Thy ſelfe thy foe,to thy ſweet ſelfe too cruell: Thou that art now the worlds freſh ornament, And only herauld to the gaudy ſpring, Within thine owne bud burieſt thy content, And tender chorle makſt waſt in niggarding:    Pitty the world,or elſe this glutton be,    To eate the worlds due,by the graue and thee.

1 个答案:

答案 0 :(得分:0)

这适用于十四行诗:)

$ sonnet="Shall I compare thee to a summer.s day?
> Thou art more lovely and more temperate.
> Rough winds do shake the darling buds of May,"

$ echo "$sonnet"
Shall I compare thee to a summer.s day?
Thou art more lovely and more temperate.
Rough winds do shake the darling buds of May,

我认为你错过了双引号。

$ echo $sonnet
Shall I compare thee to a summer.s day? Thou art more lovely and more temperate. Rough winds do shake the darling buds of May,