!/bi开发者_JAVA百科n/bash
echo Enter the num
read n
for i in { 1..10 }
do
m=$(( n*i ))
echo "$i * $n" = $m
done
i got error as
for: 8: Illegal number: { kindly suggest a solution
do it like this
#!/bin/bash
read -p "Enter the num: " n
for i in {1..10}
do
m=$(( n*i ))
echo "$i * $n" = $m
done
the shebang is wrong, and don't leave space in brace expansion eg {0..10}
, not { 0..10 }
This works in bash:
for (( i=1; i<=10; i++ )); do
# ...
done
精彩评论