I wrote a script to execute the factorial command, but I'm getting this error
((: 1 <= : syntax error: operand expected (error token is "<=")I can't fix it. The <= symbol was tried with both spaces and no spaces, but the same all the time. Below is the entire script to which the error indicated above is displayed on the 5th line
!/usr/bin/bash i=1 #nie-zero bo tworzy iloczyn wynik=1 # nie-zero bo tworzy iloczyn while (($i <= $1)) do wynik=$(($wynik * $i)) i=$(($i + 1)) done echo $wynikProszę o pomoc;(
41 Answer
You forgot to pass a parameter to your script:
$ bash -xc 'i=1; (($i <= $1))' bash 2 ; echo $?
+ i=1
+ (( 1 <= 2 ))
0but
$ bash -xc 'i=1; (($i <= $1))' bash ; echo $?
+ i=1
+ (( 1 <= ))
bash: ((: 1 <= : syntax error: operand expected (error token is "<= ")
1There is a lesson here about validating inputs...