<?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: Does double quoting a variable in echo imply a default IFS? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880681#M704033</link>
    <description>Unless told differently, spaces are variable delimiters in shell programming. Abything that produces a string with imbedded spaces will have to be quoted if the sring is to be treated as a single entity. This means during the assignment (ie, X="$(grep something)" is a single string). Then when referencing the variable, be sure to flag it as a single string with quotes too (ie, echo "$X"). The quotes don't change IFS, they flag a string as a single entity.</description>
    <pubDate>Tue, 18 Jan 2005 15:25:08 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2005-01-18T15:25:08Z</dc:date>
    <item>
      <title>Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880675#M704027</link>
      <description>I have a variable which is actually three space-delimited "fields":&lt;BR /&gt; &lt;BR /&gt;# print $arecs | vis -n&lt;BR /&gt;one\sthree\sfive\n&lt;BR /&gt;&lt;BR /&gt;Consider these outputs.&lt;BR /&gt;&lt;BR /&gt;# echo $arecs&lt;BR /&gt;one three five&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# echo ${arecs}             &lt;BR /&gt;one three five&lt;BR /&gt;&lt;BR /&gt;but why....&lt;BR /&gt;&lt;BR /&gt;# echo "$arecs"&lt;BR /&gt;one&lt;BR /&gt;three&lt;BR /&gt;five&lt;BR /&gt;&lt;BR /&gt;Does double quoting possess an un- or unclearly-documented implicit IFS?  Note that IFS was (intentionally) not set when the output above was obtained.&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Tue, 18 Jan 2005 11:25:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880675#M704027</guid>
      <dc:creator>Peter Heinemann</dc:creator>
      <dc:date>2005-01-18T11:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880676#M704028</link>
      <description>What version of HP-UX are you using?  What shell?&lt;BR /&gt;&lt;BR /&gt;I just did a test and I did NOT see the same behavior.&lt;BR /&gt;&lt;BR /&gt;# export TEST="one 2 three 4 five"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; # echo $TEST  &lt;BR /&gt;one 2 three 4 five&lt;BR /&gt;&lt;BR /&gt;# echo ${TEST}&lt;BR /&gt;one 2 three 4 five&lt;BR /&gt;&lt;BR /&gt;# echo "${TEST}"&lt;BR /&gt;one 2 three 4 five&lt;BR /&gt;&lt;BR /&gt;# echo "$TEST"  &lt;BR /&gt;one 2 three 4 five&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Jan 2005 11:39:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880676#M704028</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2005-01-18T11:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880677#M704029</link>
      <description>Patrick:&lt;BR /&gt;&lt;BR /&gt;posix under 11.11.&lt;BR /&gt;&lt;BR /&gt;more info which I inadvertently left out..&lt;BR /&gt;&lt;BR /&gt;I created the variable from output of a grep.&lt;BR /&gt;&lt;BR /&gt;Heres the source file:&lt;BR /&gt;# cat /tmp/tmp.tmp&lt;BR /&gt;one     A&lt;BR /&gt;two     B&lt;BR /&gt;three   A&lt;BR /&gt;four    B&lt;BR /&gt;five    A&lt;BR /&gt;&lt;BR /&gt;Heres the assignment:&lt;BR /&gt;arecs=$(grep "A" /tmp/tmp.tmp | cut -f 1)&lt;BR /&gt;&lt;BR /&gt;Not sure if this clarifies or further confuses...&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Jan 2005 11:43:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880677#M704029</guid>
      <dc:creator>Peter Heinemann</dc:creator>
      <dc:date>2005-01-18T11:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880678#M704030</link>
      <description>If their are newline characters between the text, then&lt;BR /&gt; &lt;BR /&gt;echo $arecs&lt;BR /&gt;will be parsed by the shell and the new lines will be seen as parameter seperaters, which will be stripped and the arguments will be displayed with the standard OFS (space).&lt;BR /&gt; &lt;BR /&gt;echo "$arecs"&lt;BR /&gt;will be parsed by the shell and the contents of arecs will not be parsed and output as is. So embedded new line characters will be displayed along with the text.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 18 Jan 2005 11:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880678#M704030</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-01-18T11:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880679#M704031</link>
      <description>Rodney,&lt;BR /&gt;&lt;BR /&gt;$arecs had:&lt;BR /&gt;one-space-two-space-three-newline&lt;BR /&gt;&lt;BR /&gt;# print $arecs | vis -n&lt;BR /&gt;one\sthree\sfive\n&lt;BR /&gt;&lt;BR /&gt;To extend your explanation a bit, with the variable in double quotes (echo "$arecs"), &lt;BR /&gt;if the shell finds *any* newline, all field separators then become newline?  e.g., the presence of one newline at the end supercedes the spaces?</description>
      <pubDate>Tue, 18 Jan 2005 12:21:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880679#M704031</guid>
      <dc:creator>Peter Heinemann</dc:creator>
      <dc:date>2005-01-18T12:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880680#M704032</link>
      <description>Your "print $arecs | vis -n" is having the same issue as the echo. The shell parser is intefering with the newline characters. Try-&lt;BR /&gt; &lt;BR /&gt;print "$arecs" | vis -n&lt;BR /&gt; &lt;BR /&gt;and I think you'll see the \n in between each text.&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 18 Jan 2005 13:37:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880680#M704032</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-01-18T13:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880681#M704033</link>
      <description>Unless told differently, spaces are variable delimiters in shell programming. Abything that produces a string with imbedded spaces will have to be quoted if the sring is to be treated as a single entity. This means during the assignment (ie, X="$(grep something)" is a single string). Then when referencing the variable, be sure to flag it as a single string with quotes too (ie, echo "$X"). The quotes don't change IFS, they flag a string as a single entity.</description>
      <pubDate>Tue, 18 Jan 2005 15:25:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880681#M704033</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-01-18T15:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880682#M704034</link>
      <description>The var assignment using $(grep ...) caused the variable to contain the newlines at the end of each 'grep'ed line (which is normal and fine, of course).&lt;BR /&gt;&lt;BR /&gt;As Bill said, when you use&lt;BR /&gt; ... # cmd "$var"&lt;BR /&gt;you are telling the shell parser that this is one argument to 'cmd' -- shell does no processing  on $var's contents and just passes it as is, newlines and all.  Thus, 'echo' sees *one* argument, including the newlines which he dutifully echoes back out.&lt;BR /&gt;&lt;BR /&gt;When you use&lt;BR /&gt; ... # cmd $var&lt;BR /&gt;the shell *is* parsing $var's contents and all whitespace, including newline, is treated as an argument delimiter and is dropped from the arguments passed to 'cmd'.  In this case, 'echo' simply sees *3* arguments, with no newlines.&lt;BR /&gt;&lt;BR /&gt;It's similar to:&lt;BR /&gt;&lt;BR /&gt;... # for x in  1 2 3 ; do echo ... $x; done  &lt;BR /&gt;... 1&lt;BR /&gt;... 2&lt;BR /&gt;... 3&lt;BR /&gt;&lt;BR /&gt;versus:&lt;BR /&gt;&lt;BR /&gt;... # for x in  "1 2 3" ; do echo ... $x; done&lt;BR /&gt;... 1 2 3&lt;BR /&gt;&lt;BR /&gt;hth&lt;BR /&gt;bv&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Jan 2005 08:15:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880682#M704034</guid>
      <dc:creator>Bob_Vance</dc:creator>
      <dc:date>2005-01-19T08:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Does double quoting a variable in echo imply a default IFS?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880683#M704035</link>
      <description>Thanks for the responses, clears it up.&lt;BR /&gt;I figured the shell was doing what it was designed to, but could get a clear description of the design...</description>
      <pubDate>Wed, 19 Jan 2005 08:54:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/does-double-quoting-a-variable-in-echo-imply-a-default-ifs/m-p/4880683#M704035</guid>
      <dc:creator>Peter Heinemann</dc:creator>
      <dc:date>2005-01-19T08:54:41Z</dc:date>
    </item>
  </channel>
</rss>

