2
!/bin/bash
echo Enter the num
read n
for i in { 1..10 }
do
m=$(( n*i ))
echo "$i * $n" = $m
done

我得到了错误

for: 8: Illegal number: { 请提出解决方案

4

2 回答 2

5

像这样做

#!/bin/bash
read -p "Enter the num: " n
for i in {1..10}
do
    m=$(( n*i ))
    echo "$i * $n" = $m
done

shebang 是错误的,并且不要在大括号扩展中留出空间,例如{0..10},不是{ 0..10 }

于 2010-02-11T10:41:28.303 回答
1

这在 bash 中有效:

for (( i=1; i<=10; i++ )); do
    # ...
done
于 2010-02-11T14:19:00.757 回答