如何在鱼壳的字符串中包含换行符?

与以下问题相同 How can I have a newline in a string in sh? 但在鱼壳里。

在bash中,我们有:

$'this is line\nthis is another line'

谁产生了预期的结果,但是在鱼中却没有效果。

鱼有类似的方法吗?

编辑1:

具有faho明智提及的文字方法:

'this is line this is another line'

但是我真的很好奇,存在像shell一样作为断行保留\n引用的方法。

我想知道是否可以使用此字符串"this is a line\nthis is another line",以确保鱼将\n视为换行符而不是文字。

totomy 回答:如何在鱼壳的字符串中包含换行符?

  1. 鱼用引号引起来的\n用换行符代替,因此您可以停止并重新启动引号(请注意在引号前不要加“ $”):

'这是一行'\ n'这是另一行'

  1. 鱼用引号引起来,因此您可以包括文字换行符:

'this is line this is another line'

,

您可以使用echo -e启用反斜杠转义的解释),如@faho在其评论中指出的那样:

$ echo -e "## Foo\nBar"
## Foo
Bar

来自man echo

转义序列

   If -e is used,the following sequences are recognized:

   o \ backslash

   o \a alert (BEL)

   o \b backspace

   o \c produce no further output

   o \e escape

   o \f form feed

   o \n new line

   o \r carriage return

   o \t horizontal tab

   o \v vertical tab

   o \0NNN byte with octal value NNN (1 to 3 digits)

   o \xHH byte with hexadecimal value HH (1 to 2 digits)
,

编辑您的config.fish文件。
Ubuntu sudo nano /etc/fish/config.fish中的示例
提示功能是控制鱼终端的外观的功能。粘贴此代码:

# Put system-wide fish configuration entries here
# or in .fish files in conf.d/
# Files in conf.d can be overridden by the user
# by files with the same name in $XDG_CONFIG_HOME/fish/conf.d

# This file is run by all fish instances.
# To include configuration only for login shells,use
# if status --is-login
#    ...
# end
# To include configuration only for interactive shells,use
# if status --is-interactive
#   ...
# end
#

function fish_prompt -d "Write out the prompt"
    # change output color
    set -U fish_color_command             '2cff8f' -o

    # Aliases
    alias cls='clear'

    # Prompt
    printf '%s@%s%s%s%s\n@>' (whoami) (hostname | cut -d . -f 1) \
                    (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end
本文链接:https://www.f2er.com/2722085.html

大家都在问