Bourne和Korn Shell中的Bash-like for-loop?
我需要读取用户的输入(Bourne和Korn Shell中的Bash-like for-loop?,for-loop,sh,ksh,portability,For Loop,Sh,Ksh,Portability,我需要读取用户的输入(N)并执行循环N次以执行一组语句。在bash中,我可以使用以下for循环语法: read N 对于((i=0;i如果您的脚本必须与Bourne shell(sh)兼容,请注意后者不提供数字的“类C”for循环语法(for((i=0;我需要使用expr;i=$(i+1))符合POSIX标准。 $ sh test.sh 3 foo foo foo $ ksh test.sh 4 foo foo foo foo $ dash test.sh # (dash is a min
N
)并执行循环N
次以执行一组语句。在bash
中,我可以使用以下for循环语法:
read N
对于((i=0;i如果您的脚本必须与Bourne shell(sh
)兼容,请注意后者不提供数字的“类C”for循环语法(for((i=0;我需要使用expr
;i=$(i+1))
符合POSIX标准。
$ sh test.sh
3
foo
foo
foo
$ ksh test.sh
4
foo
foo
foo
foo
$ dash test.sh # (dash is a minimalist, POSIX-compliant shell)
2
foo
foo