gpt4 book ai didi

string - 如何在 fish shell 中的字符串中有换行符?

转载 作者:行者123 更新时间:2023-12-04 14:16:20 24 4
gpt4 key购买 nike

是同样的问题
How can I have a newline in a string in sh?
但在 fish shell 中。

在 bash 中,我们有:
$'this is line\nthis is another line'
谁产生了预期的结果,但在 fish 中这不起作用。

fish 有类似的方法来做到这一点吗?

编辑 1:

有 faho 明智地提到的字面方法:
'this is line
this is another line'

但我真的很好奇是否存在为 \n 保留引用的方法。就像在 shell 中换行一样。

我想知道我是否可以使用这个字符串"this is a line\nthis is another line"确保 fish 会考虑\n作为换行符而不是文字。

最佳答案

  • fish 代替\n用换行符在引号之外,因此您可以停止并重新启动引号(注意引号前没有“$”):

  • '这是一行'\n'这是另一行'
  • Fish 跨行跟随引号,因此您可以包含文字换行符:
  • 'this is line
    this is another line'

    关于string - 如何在 fish shell 中的字符串中有换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59886560/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com