I want to make a while...loop statement in my Shell script like:
while [ $line < $line_number ]; do
echo $line
done
But there is an error. I think it is because I wrote it in bash
code. But I need to do it in sh
mode. How can I do it? Thanks!
You need to use, either
or
Disscussion[source]
Single
[]
are posix shell compliant condition tests.Double
[[]]
are an extension to the standard[]
and are supported by bash and other shells (e.g. zsh, ksh). They support extra operations (as well as the standard posix operations). For example:||
instead of-o
and regex matching with=~
. A fuller list of differences can be found in the bash manual section on conditional constructs.Use
[]
whenever you want your script to be portable across shells. Use[[]]
if you want conditional expressions not supported by[]
and don't need to be portable.