开发者

bash shell program

开发者 https://www.devze.com 2022-12-19 17:22 出处:网络
!/bi开发者_JAVA百科n/bash echo Enter the num read n for i in { 1..10 } do m=$(( n*i )) echo \"$i * $n\" = $m
!/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
0

精彩评论

暂无评论...
验证码 换一张
取 消