<?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: How to preserve multiple SPACE in variables -- shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276549#M179611</link>
    <description>Sorry Elmar and Clay, my mistake here, I should have the quote in echo command also,&lt;BR /&gt;not only in the C="${A}${SPACE}${B}" assignment.&lt;BR /&gt;&lt;BR /&gt;OK problem solved, thanks again guys, I should have assigned 10 points to you two, but that can't be modified, I o u one ;)&lt;BR /&gt;&lt;BR /&gt;Gary&lt;BR /&gt;</description>
    <pubDate>Fri, 14 May 2004 09:38:21 GMT</pubDate>
    <dc:creator>Gary Yu</dc:creator>
    <dc:date>2004-05-14T09:38:21Z</dc:date>
    <item>
      <title>How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276542#M179604</link>
      <description>Dear all,&lt;BR /&gt;&lt;BR /&gt;I am writing a shell script, but I had some trouble preserving mulitple SPACE inside a varible, they always got compressed to only one SPACE, e.g&lt;BR /&gt;&lt;BR /&gt;A="aaa"&lt;BR /&gt;SPACE='   '  #that's 4 space&lt;BR /&gt;B="bbb"&lt;BR /&gt;C=${A}${SPACE}${B}&lt;BR /&gt;echo $C&lt;BR /&gt;&lt;BR /&gt;for the $C, instead of "aaa    bbb", I got "aaa bbb", I don't know why shell compress the spaces?&lt;BR /&gt;&lt;BR /&gt;thanks,&lt;BR /&gt;Gary&lt;BR /&gt;</description>
      <pubDate>Fri, 14 May 2004 09:18:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276542#M179604</guid>
      <dc:creator>Gary Yu</dc:creator>
      <dc:date>2004-05-14T09:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276543#M179605</link>
      <description>hmmm, funny, spaces also got compressed by this forum ;)&lt;BR /&gt;&lt;BR /&gt;I mean, for $C, instead of "aaa----bbb" (I'm uing '-' as a place holder for SPACE), it's always "aaa bbb" just like what you saw in my first input above.</description>
      <pubDate>Fri, 14 May 2004 09:21:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276543#M179605</guid>
      <dc:creator>Gary Yu</dc:creator>
      <dc:date>2004-05-14T09:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276544#M179606</link>
      <description>Nice that the ITRC does the same as your shell ;-)&lt;BR /&gt;&lt;BR /&gt;The solution:&lt;BR /&gt;C="${A}${SPACE}${B}"&lt;BR /&gt;echo "${C}"&lt;BR /&gt;&lt;BR /&gt;Your problem is caused by the multiple arguments to echo... By enclosing it in double quotes that problem is solved. The quotes in the assignment is just precaution.</description>
      <pubDate>Fri, 14 May 2004 09:23:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276544#M179606</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-05-14T09:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276545#M179607</link>
      <description>the key is to quote the assignment statement.&lt;BR /&gt;C="${A}${SPACE}${B}"&lt;BR /&gt;&lt;BR /&gt;Note: You must use the double quotes because you want the variables to actually be instantiated. The single quotes would simply quote exactly what is within them.&lt;BR /&gt;</description>
      <pubDate>Fri, 14 May 2004 09:26:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276545#M179607</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-05-14T09:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276546#M179608</link>
      <description>thank you guys for the quick reply, but I've already tried the double quote, but still got the same problem... I'm using /usr/bin/shell on HPUX 11.0&lt;BR /&gt;&lt;BR /&gt;thanks,&lt;BR /&gt;Gary</description>
      <pubDate>Fri, 14 May 2004 09:32:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276546#M179608</guid>
      <dc:creator>Gary Yu</dc:creator>
      <dc:date>2004-05-14T09:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276547#M179609</link>
      <description>Gary,&lt;BR /&gt;&lt;BR /&gt;I did try it and with me it worked. Mind, the quotes for the echo are more important as the quotes for the assignment !!!&lt;BR /&gt;&lt;BR /&gt;But check out which echo you're calling. That could be another reason for your problem. If it's an alias, for instance, or a shell script doing some stuff, it can also destroy things.&lt;BR /&gt;&lt;BR /&gt;To check it, do:&lt;BR /&gt;type echo&lt;BR /&gt;&lt;BR /&gt;It should be 'shell builtin'.&lt;BR /&gt;&lt;BR /&gt;Rgds, Elmar</description>
      <pubDate>Fri, 14 May 2004 09:36:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276547#M179609</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-05-14T09:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276548#M179610</link>
      <description>Though I couldn't test with /usr/bin/shell. I only have /usr/bin/sh or /usr/bin/ksh.</description>
      <pubDate>Fri, 14 May 2004 09:38:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276548#M179610</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-05-14T09:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276549#M179611</link>
      <description>Sorry Elmar and Clay, my mistake here, I should have the quote in echo command also,&lt;BR /&gt;not only in the C="${A}${SPACE}${B}" assignment.&lt;BR /&gt;&lt;BR /&gt;OK problem solved, thanks again guys, I should have assigned 10 points to you two, but that can't be modified, I o u one ;)&lt;BR /&gt;&lt;BR /&gt;Gary&lt;BR /&gt;</description>
      <pubDate>Fri, 14 May 2004 09:38:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276549#M179611</guid>
      <dc:creator>Gary Yu</dc:creator>
      <dc:date>2004-05-14T09:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276550#M179612</link>
      <description>Gary &lt;BR /&gt;&lt;BR /&gt;Elmar is right.&lt;BR /&gt;Protect with echo&lt;BR /&gt;echo $C&lt;BR /&gt;aaa bbb&lt;BR /&gt;echo "$C"&lt;BR /&gt;aaa    bbb&lt;BR /&gt;&lt;BR /&gt;pipe into od&lt;BR /&gt;echo $C | od -x&lt;BR /&gt;6161 6120 6262 620a&lt;BR /&gt;&lt;BR /&gt;echo "$C" | od -x&lt;BR /&gt;6161 6120 2020 2062 6262 0a00&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc&lt;BR /&gt;</description>
      <pubDate>Fri, 14 May 2004 09:43:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276550#M179612</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-05-14T09:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276551#M179613</link>
      <description>But you are making exactly the same mistake with your echo.&lt;BR /&gt;&lt;BR /&gt;There is a marked difference in the way the shell handles&lt;BR /&gt;echo ${C}&lt;BR /&gt;and&lt;BR /&gt;echo "${C}"&lt;BR /&gt;when the instantiated variable contains whitespace. &lt;BR /&gt;what really happens if you echo ${C} is that&lt;BR /&gt;echo sees two arguments -- your ${A} and ${B} and you really want it to see only one and that is why the quotes are needed. &lt;BR /&gt;In the assignment the quotes allow you to also keep leading and trailing whitespace.&lt;BR /&gt;</description>
      <pubDate>Fri, 14 May 2004 09:43:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276551#M179613</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-05-14T09:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to preserve multiple SPACE in variables -- shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276552#M179614</link>
      <description>Well Clay,&lt;BR /&gt;&lt;BR /&gt;For some strange reason the spaces in the assingment work correctly. I tested it by doing:&lt;BR /&gt;&lt;BR /&gt;SPACE="    " #(4 spaces)&lt;BR /&gt;B="sjdhgf   " #(4 trailing spaces)&lt;BR /&gt;C=A${SPACE}${B}&lt;BR /&gt;echo "${C}k" #to make sure the trailing spaces are printed&lt;BR /&gt;&lt;BR /&gt;This gives the correct output.&lt;BR /&gt;And this isn't really as strange as it looks. The ${SPACE} worked too. If the shell had done something with it, it would have tried to execute bbb in Gary's original script with aaa assigned to C, instead of assigning "aaa    bbb" to C. That's also the reasing for the precautionary double quotes I put in the assignment. If someone tried running the script with another shell the result might be otherwise without the double quotes. With them, the result is sure as long as we are not calling scripts or aliases instead of the real commands.</description>
      <pubDate>Fri, 14 May 2004 09:57:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-preserve-multiple-space-in-variables-shell-script/m-p/3276552#M179614</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-05-14T09:57:45Z</dc:date>
    </item>
  </channel>
</rss>

