<?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: variables in bash in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211486#M10475</link>
    <description>I'm just going by what it says in the man page ;)</description>
    <pubDate>Tue, 09 Mar 2004 23:24:35 GMT</pubDate>
    <dc:creator>Stuart Browne</dc:creator>
    <dc:date>2004-03-09T23:24:35Z</dc:date>
    <item>
      <title>variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211474#M10463</link>
      <description>hey,&lt;BR /&gt;&lt;BR /&gt;I'm using bash in r.h. AS3.0 .&lt;BR /&gt;&lt;BR /&gt;in the script I declare:&lt;BR /&gt;VAR=5&lt;BR /&gt;&lt;BR /&gt;then I run a while loop that adds data to the variable, but after the loop the variable returns to be 5.&lt;BR /&gt;&lt;BR /&gt;how can I make it save the changes I have done in the loop. in sh in HP-UX11i it works, but here it doesn't work.&lt;BR /&gt;&lt;BR /&gt;thanx,&lt;BR /&gt;</description>
      <pubDate>Sun, 07 Mar 2004 06:05:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211474#M10463</guid>
      <dc:creator>Alex Lavrov</dc:creator>
      <dc:date>2004-03-07T06:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211475#M10464</link>
      <description>how about export?&lt;BR /&gt;like export &lt;VARIABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;to add a variable to a shell (across logouts):&lt;BR /&gt;&lt;BR /&gt;add a line to /etc/bashrc  (for all users)&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;to ~/.bashrc   for a specific user&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;then do logout and login..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/VARIABLE&gt;</description>
      <pubDate>Sun, 07 Mar 2004 06:12:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211475#M10464</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2004-03-07T06:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211476#M10465</link>
      <description>You mean to export every variable?&lt;BR /&gt;A bit ugly, isn't it?&lt;BR /&gt;&lt;BR /&gt;These scripts work fine in the bash of HPUX, what's the difference? Some flag maybe?</description>
      <pubDate>Sun, 07 Mar 2004 07:04:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211476#M10465</guid>
      <dc:creator>Alex Lavrov</dc:creator>
      <dc:date>2004-03-07T07:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211477#M10466</link>
      <description>Hello Alex,&lt;BR /&gt;&lt;BR /&gt;have a look at the examples in &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html#ss7.1" target="_blank"&gt;http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html#ss7.1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Works for me on Linux. If you still have problems with the script after reading this please do post a &amp;gt;&amp;gt;short&amp;lt;&amp;lt; reproducer here.&lt;BR /&gt;&lt;BR /&gt;Greetings, Martin</description>
      <pubDate>Sun, 07 Mar 2004 09:43:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211477#M10466</guid>
      <dc:creator>Martin P.J. Zinser</dc:creator>
      <dc:date>2004-03-07T09:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211478#M10467</link>
      <description>Sorry for the delay!&lt;BR /&gt;Can you post the troublemaking part of your script?</description>
      <pubDate>Sun, 07 Mar 2004 10:23:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211478#M10467</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2004-03-07T10:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211479#M10468</link>
      <description>You won't need to export your variable if you are just using in a loop in the script.&lt;BR /&gt; &lt;BR /&gt;I would assume that you have a slight loginc problem somewhere, could you post the relevant part of the script.</description>
      <pubDate>Mon, 08 Mar 2004 01:13:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211479#M10468</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-08T01:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211480#M10469</link>
      <description>I think I didn't make myself clear,&lt;BR /&gt;here the script:&lt;BR /&gt;&lt;BR /&gt;x=0&lt;BR /&gt;v="hello"&lt;BR /&gt;cat /etc/fstab | while read line&lt;BR /&gt;do&lt;BR /&gt;     x=`echo $x+1 | bc`&lt;BR /&gt;     v=$v$line     echo $v&lt;BR /&gt;done &lt;BR /&gt;echo $v&lt;BR /&gt;something like this, the output I get:&lt;BR /&gt;helloline1&lt;BR /&gt;helloline1line2&lt;BR /&gt;helloline1line2line3&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;hello&lt;BR /&gt;&lt;BR /&gt;as u can see, outside the loop, "v" stayed unchanged ...&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Mar 2004 03:22:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211480#M10469</guid>
      <dc:creator>Alex Lavrov</dc:creator>
      <dc:date>2004-03-08T03:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211481#M10470</link>
      <description>I don't pretend to understand why this happens but you can achieve what you want with the following loop and it works.&lt;BR /&gt; &lt;BR /&gt;IFS="&lt;BR /&gt;"&lt;BR /&gt;x=0;&lt;BR /&gt;v="hello"&lt;BR /&gt;for line in `cat /etc/fstab`&lt;BR /&gt;do&lt;BR /&gt;        (( x = x + 1 ))&lt;BR /&gt;        v=$v$line&lt;BR /&gt;        echo "$v"&lt;BR /&gt;done&lt;BR /&gt;echo "LAST ONE $v"&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Mar 2004 03:45:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211481#M10470</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-08T03:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211482#M10471</link>
      <description>well, probably it happens because of the pipe ... but in HPUX11.11 it works fine.</description>
      <pubDate>Mon, 08 Mar 2004 05:24:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211482#M10471</guid>
      <dc:creator>Alex Lavrov</dc:creator>
      <dc:date>2004-03-08T05:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211483#M10472</link>
      <description>This look like some kind of bug with bash.  I tried it using bash on HPUX and it still fails.  I tried it using /bin/sh and it works fine.&lt;BR /&gt; &lt;BR /&gt;If behaves as if the "cat /etc/fstab | while read line" is creating a subshell which it may well do.  However, if this is the case, then increasing the value of "x" at initialization would have no effect but it does.  Also, exporting "v" would solve the problem but it doesn't.&lt;BR /&gt; &lt;BR /&gt;On the other hand, I've never really trusted piping into my own script so maybe I'll stick with that distrust :)&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Mar 2004 05:43:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211483#M10472</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-08T05:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211484#M10473</link>
      <description>Nup, not a bug.  We discussed this recently in the thread &lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=478229" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=478229&lt;/A&gt; here.&lt;BR /&gt;&lt;BR /&gt;Basically, any commands executed in pipe are executed as a SubShell, thus environment variables changed within the pipe (read: subshell) stay there.</description>
      <pubDate>Mon, 08 Mar 2004 19:51:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211484#M10473</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-08T19:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211485#M10474</link>
      <description>Stuart, &lt;BR /&gt; &lt;BR /&gt;This is how it looked to me too BUT if it really is being run in a sub-shell, you would expect that setting $x to say 10 and not exporting it would have no effect on the loop in the pipe.  However, it does.  *shrug*&lt;BR /&gt; &lt;BR /&gt;I would be interested to know what is "correct".  Personally I think that "bash" is wrong here because the posix complient shell on hpux does not have this behaviour. It works as you would expect.</description>
      <pubDate>Tue, 09 Mar 2004 01:22:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211485#M10474</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-09T01:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211486#M10475</link>
      <description>I'm just going by what it says in the man page ;)</description>
      <pubDate>Tue, 09 Mar 2004 23:24:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211486#M10475</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-09T23:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211487#M10476</link>
      <description>But how it works on HPUX?&lt;BR /&gt;I'm runnig sh on both of them, HPUX and linux.</description>
      <pubDate>Wed, 10 Mar 2004 02:26:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211487#M10476</guid>
      <dc:creator>Alex Lavrov</dc:creator>
      <dc:date>2004-03-10T02:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211488#M10477</link>
      <description>Umm, in your original post, you said 'bash in r.h. AS3.0'.&lt;BR /&gt;&lt;BR /&gt;It won't increment it within a piped loop on Linux (using bash), or using pdksh.&lt;BR /&gt;&lt;BR /&gt;As for other shells, I can't guarantee.&lt;BR /&gt;&lt;BR /&gt;sh/ksh on HPUX is a different story.</description>
      <pubDate>Wed, 10 Mar 2004 18:04:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211488#M10477</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-10T18:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: variables in bash</title>
      <link>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211489#M10478</link>
      <description>.. just for the sake of experiment ..&lt;BR /&gt;&lt;BR /&gt;your routine there could do what you expect it if you not use a pipe, i.e.&lt;BR /&gt;&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;&lt;STUFF&gt;&lt;BR /&gt;done &amp;lt; /etc/fstab&lt;/STUFF&gt;</description>
      <pubDate>Thu, 11 Mar 2004 00:12:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/variables-in-bash/m-p/3211489#M10478</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-11T00:12:49Z</dc:date>
    </item>
  </channel>
</rss>

