views:

66

answers:

2
+2  Q: 

bash shell program

!/bin/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

+5  A: 

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 }

ghostdog74
Could you please also tell me how could we do it in ksh.{0..10} is not valid is ksh
Vijay Sarathi
@benjamin You could always use the standard seq command like: "for i in $(seq 1 10); do echo $i; done"
Johan
@benjamin, my ksh version supports brace expansion. you can try `ksh -o braceexpand ` or `set -o braceexpand` in your script.
ghostdog74
+1  A: 

This works in bash:

for (( i=1; i<=10; i++ )); do
    # ...
done
glenn jackman