我想知道是否有一种方法可以让zsh中的内联循环像bash中的一样。
我最近开始使用zsh,到目前为止我很喜欢它。在zsh中有一件事我希望能像在bash中一样,内联循环。
我经常运行这样的快速循环:for in a b c
-> hit enter -> do
-> hit enter等等…
当我回想起在zsh中要更改的命令/循环时,行被包装成多行,但在bash中它只是一行。
ZSH initial run:
user@localhost > for i in {a..c}
for> do
for> echo ${i}
for> done
a
b
c
ZSH repeat <向上箭头>:向上箭头>
user@localhost > for i in {a..c}
do
echo ${i}
done
BASH初始运行:
[user@localhost ~]$ for i in {a..c}
> do
> echo ${i}
> done
a
b
c
BASH repeat <向上箭头>:向上箭头>
[user@localhost ~]$ for i in {a..c}; do echo ${i}; done
在Zsh指南中有一个可爱的选项:它是singlelinezle
选项;设置这个会导致"…编辑为[被限制到]一行,"启用您在问题中提到的所需行为。
# without `singlelinezle` set
user% for a in a b c; do echo $a; done
# output:
# a
# b
# c
# <up-arrow>
user% for a in a b c; do echo $a; done
user% for a in a b c; do
for> echo $a;
for> done
# output:
# a
# b
# c
# <up-arrow>
user% for a in a b c; do
echo $a
done
setopt singlelinezle
# with `singlelinezle` set
user% for a in a b c; do echo $a; done
# output:
# a
# b
# c
# <up-arrow>
user% for a in a b c; do echo $a; done
user% for a in a b c; do
for> echo $a
for> done
# output:
# a
# b
# c
# <up-arrow>
user% for a in a b c; donecho $andone
unsetopt singlelinezle