<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: String to numeric in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103124#M90994</link>
    <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;It is helpful in scripts to add 'set -u' which causes the shell to treat unset parameters as an error when substituting them.  Had you done this with this script:&lt;BR /&gt;&lt;BR /&gt;# cat ./myexpr&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;dt=20081125&lt;BR /&gt;dttb="20081126"&lt;BR /&gt;if [ `expr "$dtb" - "$dt"` -eq 1 ]; then&lt;BR /&gt;echo "converting"&lt;BR /&gt;else&lt;BR /&gt;echo "not converting"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;...when you ran it, your output would be:&lt;BR /&gt;&lt;BR /&gt;#./myexpr&lt;BR /&gt;./myexpr[5]: dtb: Parameter not set.&lt;BR /&gt;./myexpr[5]: test: Specify a parameter with this command.&lt;BR /&gt;not converting&lt;BR /&gt;&lt;BR /&gt;This tells you that something is amiss since a "Parameter [is] not set".   As noted, originally, the correct line is:&lt;BR /&gt;&lt;BR /&gt;if [ `expr "$dttb" - "$dt"` -eq 1 ]; then&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Sun, 13 Apr 2008 18:28:27 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2008-04-13T18:28:27Z</dc:date>
    <item>
      <title>String to numeric</title>
      <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103122#M90992</link>
      <description>Hi everybody,&lt;BR /&gt;&lt;BR /&gt;I have a simple script as below&lt;BR /&gt;&lt;BR /&gt;dt=20081125&lt;BR /&gt;dttb="20081126"&lt;BR /&gt;if [ `expr "$dt" - "$dtb"` -eq 1 ]; then&lt;BR /&gt;   echo "converting"&lt;BR /&gt;  else&lt;BR /&gt;  echo "not converting"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;How do i convert the variable "dttb" to a numeric,i tried something like this sed 's/"//g' but still no success.&lt;BR /&gt;&lt;BR /&gt;I want the bash script if statement to evaluate to true.How do i do this? I searched the forum  but did not get any positive result.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan&lt;BR /&gt;</description>
      <pubDate>Sun, 13 Apr 2008 16:09:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103122#M90992</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-04-13T16:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: String to numeric</title>
      <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103123#M90993</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;First, you mis-spelled one of your variables --- once it is 'dttb' and once it is 'dtb'.&lt;BR /&gt;&lt;BR /&gt;Second, it appears that you are subtracting the larger value from the smaller and then expecting the result to be a postive value.&lt;BR /&gt;&lt;BR /&gt;Try something like:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;dt=20081125&lt;BR /&gt;dttb="20081126"&lt;BR /&gt;if [ `expr "$dttb" - "$dt"` -eq 1 ]; then&lt;BR /&gt;echo "converting"&lt;BR /&gt;else&lt;BR /&gt;echo "not converting"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;...which when run, outputs"&lt;BR /&gt;&lt;BR /&gt;converting&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 13 Apr 2008 18:12:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103123#M90993</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-04-13T18:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: String to numeric</title>
      <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103124#M90994</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;It is helpful in scripts to add 'set -u' which causes the shell to treat unset parameters as an error when substituting them.  Had you done this with this script:&lt;BR /&gt;&lt;BR /&gt;# cat ./myexpr&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;dt=20081125&lt;BR /&gt;dttb="20081126"&lt;BR /&gt;if [ `expr "$dtb" - "$dt"` -eq 1 ]; then&lt;BR /&gt;echo "converting"&lt;BR /&gt;else&lt;BR /&gt;echo "not converting"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;...when you ran it, your output would be:&lt;BR /&gt;&lt;BR /&gt;#./myexpr&lt;BR /&gt;./myexpr[5]: dtb: Parameter not set.&lt;BR /&gt;./myexpr[5]: test: Specify a parameter with this command.&lt;BR /&gt;not converting&lt;BR /&gt;&lt;BR /&gt;This tells you that something is amiss since a "Parameter [is] not set".   As noted, originally, the correct line is:&lt;BR /&gt;&lt;BR /&gt;if [ `expr "$dttb" - "$dt"` -eq 1 ]; then&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 13 Apr 2008 18:28:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103124#M90994</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-04-13T18:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: String to numeric</title>
      <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103125#M90995</link>
      <description>&amp;gt;How do i convert the variable "dttb" to a numeric&lt;BR /&gt;&lt;BR /&gt;If using a real shell, you should use the Arithmetic Evaluation operator:&lt;BR /&gt;if [ $((dt - dttb)) -eq 1 ]; then&lt;BR /&gt;&lt;BR /&gt;You can also use it for the whole expression:&lt;BR /&gt;if (( dt - dttb == 1 )); then&lt;BR /&gt;&lt;BR /&gt;(Unfortunately I can't remember if the result of this expression is 1 for C, so that the "if" will then be false?)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;JRF: it appears that you are subtracting the larger value from the smaller and then expecting&lt;BR /&gt;&lt;BR /&gt;I assume Gyankr cares about is the answer 1.  Perhaps with that negative result, Gyankr wants to test the false case?  :-)</description>
      <pubDate>Mon, 14 Apr 2008 00:35:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103125#M90995</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-04-14T00:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: String to numeric</title>
      <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103126#M90996</link>
      <description>Thanks especially to JRF,it was a simple variable mistake.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan</description>
      <pubDate>Mon, 14 Apr 2008 05:58:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103126#M90996</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-04-14T05:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: String to numeric</title>
      <link>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103127#M90997</link>
      <description>&amp;gt;ME: if (( dt - dttb == 1 )); then&lt;BR /&gt;&amp;gt;(Unfortunately I can't remember if the result of this expression is 1 for C,&lt;BR /&gt;&lt;BR /&gt;It works fine.  The exit status of let is 0 if the result is non-zero.</description>
      <pubDate>Mon, 14 Apr 2008 23:51:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/string-to-numeric/m-p/5103127#M90997</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-04-14T23:51:18Z</dc:date>
    </item>
  </channel>
</rss>

