Topic
  • 2 replies
  • Latest Post - ‏2005-01-18T07:11:22Z by SystemAdmin
SystemAdmin
SystemAdmin
232 Posts

Pinned topic need help

‏2004-11-02T09:21:24Z |
am not getting the desired result on the following:

#!/bin/bash
  1. FILE: parm1
VAL='expr ${1:-0}+${2:-0}+${3:-0}'
echo "The answer is $VAL"
user1@st shells$ add.sh 2 3 4
The answer is expr ${1:-0}+${2:-0}+${3:-0}

why am i getting this, instead of
The answer is 9
Updated on 2005-01-18T07:11:22Z at 2005-01-18T07:11:22Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    232 Posts

    Re: need help

    ‏2004-11-08T20:10:32Z  
    first of all use `` instead of '', and then have fun with mathematics..
  • SystemAdmin
    SystemAdmin
    232 Posts

    Re: need help

    ‏2005-01-18T07:11:22Z  
    Change your script like this

    #!/bin/bash
    1. FILE: parm1
    VAL=`expr ${1:-0} + ${2:-0} + ${3:-0}`
    echo "The answer is $VAL"