2 Replies - 299 Views - Last Post: 30 April 2013 - 05:54 AM Rate Topic: -----

#1 billyv123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-August 08

UNIX Can you assign an operator to a variable?

Posted 30 April 2013 - 03:07 AM

I want to use an operator, but want to choose it based on a case statement.

Is this possible? What reading would you recommend?
Is This A Good Question/Topic? 0
  • +

Replies To: UNIX Can you assign an operator to a variable?

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,703
  • Joined: 16-October 07

Re: UNIX Can you assign an operator to a variable?

Posted 30 April 2013 - 03:24 AM

UNIX isn't a language, it's an Operating System.

What language are you using? If it's a shell script, then what flavor: sh, ksh, csk, bash, etc.
Was This Post Helpful? 1
  • +
  • -

#3 billyv123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-August 08

Re: UNIX Can you assign an operator to a variable?

Posted 30 April 2013 - 05:54 AM

It is ksh.

I figured it out.

I was able to assign the operator to a variable and call on it after my case structure.

Example:



NumOne=1
NumTwo=2

echo "Select a Choice:"

read CHOICE

case $CHOICE
in

1)
Operator="+"
;;

2)
Operator="-"
;;

esac

((TotalNum= NumOne $Operator NumTwo))
Echo "$TotalNum"




Thank you for the quick response though! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1