为什么写在一行上时;
,do
在 shell 循环之后没有一个字符?
这就是我的意思。当写在多行上时,for
循环看起来像:
$ for i in $(jot 2)
> do
> echo $i
> done
Run Code Online (Sandbox Code Playgroud)
在一行上:
$ for i in $(jot 2); do echo $i; done
Run Code Online (Sandbox Code Playgroud)
除了该行之外,所有折叠的行;
后面都有一个do
,如果包含;
,则是一个错误。可能比我聪明得多的人认为这是正确的做法是有原因的,但我不知道原因是什么。这对我来说似乎不一致。
用相同的while
循环了。
$ while something
> do
> anotherthing
> done
$ while something; do anotherthing; done
Run Code Online (Sandbox Code Playgroud) shell ×1