Reputation: 31
This is my code
echo "multiplication table"
echo "enter number"
read n
m=0
for((j=1;j<=12;j++))
do
echo -n -e " $j\t"
done
echo ""
echo
for((i=1;i<=n;i++))
do
for((k=1;k<=12;k++))
do
m=` expr $k \* $i `
echo -n -e " $m\t"
done
echo ""
done
When I run this I got:
malathy@malathy:~/Desktop/fosslab/20084664/shell$ sh matrix.sh
multiplication table
enter number
2
matrix.sh: 5: Syntax error: Bad for loop variable
Can anyone help me to solve this?
Upvotes: 0
Views: 30645
Reputation: 11
try this for multiplication simple and easy
echo Enter the multiplication number required:
read number
for i in 1 2 3 4 5 6 7 8 9 10
do
echo "$number * $i =`expr $number \* $i`"
done
Upvotes: 1
Reputation: 360133
You're running a script that uses syntax that is not supported in the shell you're using. Either change the first line of your script to:
#!/bin/bash
The Korn shell (at least some versions) and zsh also support the form of the for
statement.
If you're using the Bourne shell (or something vary close like Dash), you need to change the for
statement to use seq
or jot
:
for i in `seq $n`
or
for i in `jot $n`
Upvotes: 1
Reputation: 7691
This syntax isn't supported in all shells:
for((j=1;j<=12;j++))
Try this instead:
for j in {1..12}
Upvotes: 0