bash - while looking for matching line 27: syntax error: unexpected end of file -


i trying create multiply table using loop don't know how initialize variables , if read variable needs same in loop

syntax: #!/bin/bash #multiplication table #$#=parameter given script #$i=variable in loop #$1=variable represents valid number not 0 #$0=variable represents bash script name  echo "enter number want multiply" read varnumber echo "this number: $varnumber has multiplication result:  if [ $varnumber -eq 0 ] echo "error - number missing command line argument" echo "syntax : $0 number" echo "use print multiplication table given number" exit 1 fi  n=$varnumber in 1 2 3 4 5 6 7 8 9 10 echo "$varnumber * $i = `expr $i \* $varnumber`" 

a loop should end done, :

for in 1 2 3 4 5 6 7 8 9 10 echo "$varnumber * $i = `expr $i \* $varnumber`" done  #line added 

also there no harm in doing :

n="$varnumber"  

and note backticks (` `) not preferred in bash. use command $() format instead this reason. :

echo "$varnumber * $i = $(expr $i \* $varnumber)" # used $() syntax. 

see obsolete in bash.

in fact, better if can finish job without expr external command:

echo "$varnumber * $i = $((i * varnumber))" # faster previous version 

(thanks @benjamin-w suggestion)


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -