I want to print messages entered through the terminal, so I defined a function called print
. But when I ran this script, I got such error message:
./hello.sh: line 17: {0..1}: syntax error: operand expected (error token is "{0..1}")
I changed the expression {0..$(( $#-1 ))}
to {0..1}
, and the scripts ran successfully, but after I changed it back, the same error emerged again. Can anybody tell me the reason behind it? My code is here:
#!/usr/bin/bash
args=("$@")
length=$(( $#-1 ))
function print() {
echo $@
}
for i in {0..$length}
do
print ${args[$i]}
done
I changed the expression {0..$(( $#-1 ))}
to {0..1}
, the scripts ran successfully, but after I changed it back, the same error emerged again. Can anybody tell me the reason behind it?