LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   assigning a value with special characters (http://www.linuxquestions.org/questions/linux-general-1/assigning-a-value-with-special-characters-4175413597/)

nano2 06-27-2012 03:27 AM

assigning a value with special characters
 
Have the following scenario where by i have a mixture of integer values and special chars in a value and want to assign it to another value .

Code:


value1 = 3,6789

value2= $value1

expected  value2 = 3,6789

actual value2 '3 6789' is not a valid integer

using GNU bash, version 3.2.25

Any ideas how to solve this ?

catkin 06-27-2012 09:46 AM

IDK where "actual value2 '3 6789' is not a valid integer" comes from ... ?

The bash assignment operator "=" must not have space either side of it so the code should be
Code:

value1=3,6789

value2=$value1

That will work but 3,6789 is not a valid integer; use 36789 instead.

nano2 06-27-2012 12:28 PM

I need the comma in it .
I have tried douuble quotes but then i get a comma replaced with a space

Any ideas to get this value2=3,6789

pan64 06-27-2012 02:18 PM

I have tried and worked for me:
Code:

a=3,2345234
echo $a
3,2345234
b=$a
echo $b
3,2345234

just remove space before and after =


All times are GMT -5. The time now is 10:23 AM.