Skip to main content
added 284 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

There are four things in your script that you should consider changing. Two of them are syntax related:

  1. Assignments can not have spaces around =. You have this error in two places.
  2. To do an arithmetic less than or equal test, use -lt, not <=. The <= is an input redirection from a file called =. This is where your "no such file" error comes from.

The other two are:

  1. Always double quote expansion. Use echo "$n" or printf '%s\n' "$n" instead of echo $n. Use [ "$n" -lt 99 ] instead of [ $n -lt 99 ]. In the general case, the shell would otherwise split the variable's value into words and apply filename globbing rules to each of those words.
  2. You don't need declare -i here. Declaring a variable as integer in bash is very rarely needed.

Additionally, since you get a "declare not found" error, you are likely not running the script with bash. Do consider making your script executable and also don't specify an explicit interpreter on the command line when you run your script (this would make the #! line take effect).

See also:

There are four things in your script that you should consider changing. Two of them are syntax related:

  1. Assignments can not have spaces around =. You have this error in two places.
  2. To do an arithmetic less than or equal test, use -lt, not <=. The <= is an input redirection from a file called =.

The other two are:

  1. Always double quote expansion. Use echo "$n" or printf '%s\n' "$n" instead of echo $n. Use [ "$n" -lt 99 ] instead of [ $n -lt 99 ]. In the general case, the shell would otherwise split the variable's value into words and apply filename globbing rules to each of those words.
  2. You don't need declare -i here. Declaring a variable as integer in bash is very rarely needed.

See also:

There are four things in your script that you should consider changing. Two of them are syntax related:

  1. Assignments can not have spaces around =. You have this error in two places.
  2. To do an arithmetic less than or equal test, use -lt, not <=. The <= is an input redirection from a file called =. This is where your "no such file" error comes from.

The other two are:

  1. Always double quote expansion. Use echo "$n" or printf '%s\n' "$n" instead of echo $n. Use [ "$n" -lt 99 ] instead of [ $n -lt 99 ]. In the general case, the shell would otherwise split the variable's value into words and apply filename globbing rules to each of those words.
  2. You don't need declare -i here. Declaring a variable as integer in bash is very rarely needed.

Additionally, since you get a "declare not found" error, you are likely not running the script with bash. Do consider making your script executable and also don't specify an explicit interpreter on the command line when you run your script (this would make the #! line take effect).

See also:

Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

There are four things in your script that you should consider changing. Two of them are syntax related:

  1. Assignments can not have spaces around =. You have this error in two places.
  2. To do an arithmetic less than or equal test, use -lt, not <=. The <= is an input redirection from a file called =.

The other two are:

  1. Always double quote expansion. Use echo "$n" or printf '%s\n' "$n" instead of echo $n. Use [ "$n" -lt 99 ] instead of [ $n -lt 99 ]. In the general case, the shell would otherwise split the variable's value into words and apply filename globbing rules to each of those words.
  2. You don't need declare -i here. Declaring a variable as integer in bash is very rarely needed.

See also: