String 我怎么能在鱼壳里有一条线呢?
这个问题和 但是在鱼壳里 在bash中,我们有:String 我怎么能在鱼壳里有一条线呢?,string,line-breaks,fish,String,Line Breaks,Fish,这个问题和 但是在鱼壳里 在bash中,我们有: $“这是一行\n这是另一行” 谁能产生预期的结果,但在鱼身上却不起作用 鱼也有类似的方法来做到这一点 编辑1: faho明智地提到了文字法: ”这是一行 这是另一行“ 但是我真的很好奇有没有一种方法像在shell中一样将\n的引用保留为换行符 我想知道我是否可以使用这个字符串“这是一条线,这是另一行”< /C> >确保鱼会考虑 \n>代码>作为断线而不是文字。< /P> Fish将引号外的\n替换为换行符,因此您可以停止并重新启动引号(请注意引号
$“这是一行\n这是另一行”
谁能产生预期的结果,但在鱼身上却不起作用
鱼也有类似的方法来做到这一点
编辑1:
faho明智地提到了文字法:
”这是一行
这是另一行“
但是我真的很好奇有没有一种方法像在shell中一样将\n
的引用保留为换行符
我想知道我是否可以使用这个字符串<代码>“这是一条线,这是另一行”< /C> >确保鱼会考虑<代码> \n>代码>作为断线而不是文字。< /P>
\n
替换为换行符,因此您可以停止并重新启动引号(请注意引号前没有“$”):”这是一行
这是另一行“
您可以使用echo-e
(启用反斜杠转义的解释),正如@faho在其评论中指出的:
$ echo -e "## Foo\nBar"
## Foo
Bar
从人工回声
:
逃逸序列
编辑
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
#将系统范围的fish配置条目放在此处
#或者在conf.d中的.fish文件中/
#conf.d中的文件可以被用户覆盖
#通过$XDG\u CONFIG\u HOME/fish/conf.d中同名的文件
#此文件由所有fish实例运行。
#要仅包含登录shell的配置,请使用
#如果status--is login
# ...
#结束
#要仅包含交互式Shell的配置,请使用
#如果状态是交互式的
# ...
#结束
#
函数fish_prompt-d“写出提示”
#更改输出颜色
设置-U fish\U color\U命令'2cff8f'-o
#别名
别名cls='clear'
#提示
printf“%s@%s%s%s%s\n@>”(whoami)(主机名| cut-d.-f 1)\
(设置颜色$fish_color_cwd)(提示_pwd)(设置颜色正常)
结束
谢谢你花时间回答这个问题。我也可以在shell中使用这种方式。有其他方法可以像在shell中一样保留“\n”吗?不,在“shell”中不能这样做。类似于POSIX的shell不会解释\n
之外的$'
-echo'a'\n'b'
打印anb
。在fish和POSIX shell中,echo-e
也会解释字符串中的反斜杠转义,因此echo-e'a\nb'
也会打印a、新行和b。我建议你只使用我给你的第一种方法,因为不管你把论点传给什么,这都是可行的。有趣的是,多谢的鱼设计博士很有趣,现在我明白了鱼壳在这方面的立场。
# 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