0

I am writing a program in UNIX which doubles a number

if [ $# == l ]; then
  let "twice=$l*2

if [ $? == 0 ]; then
   clear
   echo "twice Program"
   echo "-------------"
   echo "l * 2 = $twice"
   exit 0
 else
   clear
   echo "The argument must be an integer."
   exit 1
 fi

 exit 0
else
 clear
 echo "Only one argument is acceptable with twice."
 echo :Usage: twice argument"
 exit 1
fi
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Beth
  • 21
  • 8

2 Answers2

0

You are opening a double quote in line two which isn't properly closed.

  let "twice=$l*2

Should be

  let "twice=$1*2"

The shell interpreter choke later when dealing with unrelated double quotes.

Note that you are also confusing the letter l (ell) with the number 1 (one) at several places, which isn't going the shell to understand your script.

jlliagre
  • 29,783
  • 6
  • 61
  • 72
  • That was a typo when typing the question to stackoverflow – Beth Sep 14 '14 at 13:43
  • Then please correct all of the remaining ones still there. – jlliagre Sep 14 '14 at 13:48
  • if [ $# == l ]; then let "twice=$l*2" fi if [ $? == 0 ]; then clear echo "twice Program" echo "-------------" echo "l * 2 = $twice" exit 0 else clear echo "The argument must be an integer." exit 1 fi exit 0 else clear echo "Only one argument is acceptable with twice." echo :Usage: twice argument" exit 1 fi – Beth Sep 14 '14 at 15:35
  • Now it just shows twice.sh Program -------------------------------- *2 = – Beth Sep 14 '14 at 15:37
0

You are using l (small L) instead of 1

if [ $# ==  1 ]
then
  let "twice=$1*2"
  if [ $? == 0 ]; then
     echo "twice Program"
     clear
     echo "-------------"
     echo "$1 * 2 = $twice"
     exit 0
 else
     clear
     echo "The argument must be an integer."
     exit 1
 fi

 exit 0
 else
   clear
   echo "Only one argument is acceptable with twice."
   echo ":Usage: twice argument"
   exit 1
fi
DS.
  • 604
  • 2
  • 6
  • 24