Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assigning strings in conditional expressions

Status
Not open for further replies.

hariceg

Programmer
Jun 1, 2013
2
US
Hi all,

I have a newbie question :) I am trying to assign a string to a variable in a conditional expression as follows

set range_a "5:4"
set range_b "3:2"
set range_c "1:0"

set range [expr ($i==0) ? $range_a : ($i==1) ? $range_b : $range_c]

I get the following error

unexpected operator ":" without preceding "?"
in expression "... ? 5:4 : (1==1) ? 3:2 : 1:0"
(parsing expression "(1==0) ? 5:4 : (1==1) ...")
invoked from within
"expr ($i==0) ? $range_a : ($i==1) ? $range_b : $range_c"

It is basically not treating range_a/range_b as strings - Could you please suggest a way to get this to work?

Thanks a lot in advance!
 
try escaping the colon: "\:"

_________________
Bob Rashkin
 
Hi bong - escaping the colon didnt work - The following did work though

set range [expr ($i==0) ? \"$range_a\" : ($i==1) ? \"$range_b\" : \"$range_c\"]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top