<?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: typeset usage in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937201#M762886</link>
    <description>Sangeeta,&lt;BR /&gt;I would always be careful useing typeset variables and have not found a definite need for them, as yet.&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;# typeset -i a&lt;BR /&gt;# a=0.4&lt;BR /&gt;# echo $a&lt;BR /&gt;0&lt;BR /&gt;# b=0.4   &lt;BR /&gt;# echo $b&lt;BR /&gt;0.4&lt;BR /&gt;# &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 02 Feb 2007 07:28:14 GMT</pubDate>
    <dc:creator>Peter Godron</dc:creator>
    <dc:date>2007-02-02T07:28:14Z</dc:date>
    <item>
      <title>typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937200#M762885</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am working on code porting from tru64 to hp-ux.&lt;BR /&gt;I want to know what would i benefit if i use a typeset to variable before i use it.&lt;BR /&gt;or rather when should we use variables after doing typeset for it and when to use it without doing a typeset.&lt;BR /&gt;Also does it have different impact on different unix systems.&lt;BR /&gt;Thanks and Regards,&lt;BR /&gt;Sangeeta&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Feb 2007 07:22:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937200#M762885</guid>
      <dc:creator>Sangeeta Gupta</dc:creator>
      <dc:date>2007-02-02T07:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937201#M762886</link>
      <description>Sangeeta,&lt;BR /&gt;I would always be careful useing typeset variables and have not found a definite need for them, as yet.&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;# typeset -i a&lt;BR /&gt;# a=0.4&lt;BR /&gt;# echo $a&lt;BR /&gt;0&lt;BR /&gt;# b=0.4   &lt;BR /&gt;# echo $b&lt;BR /&gt;0.4&lt;BR /&gt;# &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Feb 2007 07:28:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937201#M762886</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-02-02T07:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937202#M762887</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Using 'typeset' for your variables allows you to do:&lt;BR /&gt;&lt;BR /&gt;1. Faster arithmetic (if declared a s an integer).&lt;BR /&gt;&lt;BR /&gt;2. To perform automatic upper/lower case translations when you store into the variable, eliminating testing for "Y" or "y" or "N" or "n", for example.&lt;BR /&gt;&lt;BR /&gt;3. To right or left justify and fill will blanks or zeros.&lt;BR /&gt;&lt;BR /&gt;4.  Declare read-only variables so that you can logically treat them as constants.&lt;BR /&gt;&lt;BR /&gt;5.  Create local variables within subroutines.&lt;BR /&gt;&lt;BR /&gt;These implementions are common among the POSIX, ksh, and bash shells.  Obviously, there is great benefit to using 'typeset'.&lt;BR /&gt;&lt;BR /&gt;If you code in a C or Perl, 'typeset' feels like a "natural" thing to do.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 02 Feb 2007 07:44:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937202#M762887</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-02-02T07:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937203#M762888</link>
      <description>&lt;!--!*#--&gt;Apart from what James already has mentioned,&lt;BR /&gt;probably the biggest asset of typesetting shell variables is that it lets you scope variables to avoid inadvertent name clashes like in proper programming languages (even untyped ones like Perl, otherwise no CPAN was possible at all).&lt;BR /&gt;&lt;BR /&gt;You may already have noticed these neat alii that HP compiled into their sh:&lt;BR /&gt; &lt;BR /&gt;$ alias autoload functions integer local&lt;BR /&gt;autoload='typeset -fu'&lt;BR /&gt;functions='typeset -f'&lt;BR /&gt;integer='typeset -i'&lt;BR /&gt;local=typeset&lt;BR /&gt;  &lt;BR /&gt;So you could use typeset (or the aliased local) for local scoping in function definitions like this:&lt;BR /&gt;  &lt;BR /&gt;$ scope() { var=blah;echo $var; };scope;echo ${var:-unset};unset -f scope;unset var&lt;BR /&gt;blah&lt;BR /&gt;blah&lt;BR /&gt; &lt;BR /&gt;$ scope() { typeset var=blah;echo $var; };scope;echo ${var:-unset};unset -f scope;unset var&lt;BR /&gt;blah&lt;BR /&gt;unset&lt;BR /&gt; &lt;BR /&gt;You can also temporarily export variables&lt;BR /&gt;whithout much ado&lt;BR /&gt;&lt;BR /&gt;$ var=blah printenv var;printenv var;printenv var;unset var &lt;BR /&gt;blah&lt;BR /&gt;&lt;BR /&gt;I like the auto case conversion already mentioned by James.&lt;BR /&gt;&lt;BR /&gt;$ typeset -u uc_pwd=$PWD; echo $uc_pwd&lt;BR /&gt;/ETC/RC.CONFIG.D&lt;BR /&gt;&lt;BR /&gt;likewise in lower case&lt;BR /&gt;&lt;BR /&gt;$ typeset -l lc_pwd=$uc_pwd;echo $lc_pwd&lt;BR /&gt;/etc/rc.config.d&lt;BR /&gt;&lt;BR /&gt;Integer arithmetics are accomplished without fussy bracing etc.&lt;BR /&gt;&lt;BR /&gt;$ typeset -i i=0;while ((i&amp;lt;=10));do a[i+=1]="$((10-i))\n";done;echo ${a[*]}       &lt;BR /&gt;10&lt;BR /&gt; 9&lt;BR /&gt; 8&lt;BR /&gt; 7&lt;BR /&gt; 6&lt;BR /&gt; 5&lt;BR /&gt; 4&lt;BR /&gt; 3&lt;BR /&gt; 2&lt;BR /&gt; 1&lt;BR /&gt; 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You can also declare read only variables which may act similar to constants.&lt;BR /&gt;&lt;BR /&gt;$ typeset -r const="won't change";const="take this"&lt;BR /&gt;const: This variable is read only.&lt;BR /&gt; &lt;BR /&gt;Enough reasons I would think to more often make use of typeset.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Feb 2007 09:47:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937203#M762888</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-02-02T09:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937204#M762889</link>
      <description>The major portability stubling block that I have found involves the typeset -i syntax. Some implementations allow this construct:&lt;BR /&gt;typeset -i8 OCTALVAR=1 &lt;BR /&gt;so that a base/radix can be declared rather than the default base10.&lt;BR /&gt;&lt;BR /&gt;typeset -i VAR=1 works everywhere (Korn, POSIX, bash, zsh) but typeset -i10 works in some implementations but not others. I would avoid integer declaration with a base specification although that can be an extremely useful construct in some cases.&lt;BR /&gt;&lt;BR /&gt;In any event, typeset should be used for exactly the same reasons that strongly typed languages are favored. If you use them nowhere else, at least use them within functions so that you can use local variables without fear of side-effects.</description>
      <pubDate>Fri, 02 Feb 2007 10:31:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937204#M762889</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-02-02T10:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937205#M762890</link>
      <description>&amp;gt;Clay: Some implementations allow this construct:&lt;BR /&gt;typeset -i8 OCTALVAR=1&lt;BR /&gt;so that a base/radix can be declared rather than the default base10.&lt;BR /&gt;&lt;BR /&gt;Yes, we allow that.  Also if you want to convert from hex:&lt;BR /&gt;typeset -i10 fromhex=16#dead; echo $fromhex</description>
      <pubDate>Sat, 03 Feb 2007 01:03:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937205#M762890</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-03T01:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937206#M762891</link>
      <description>Yes Dennis, I'm well aware of that. I was merely trying to point out that while the "typeset -i" works everywhere the "typeset -iN" is not very portable (though useful).</description>
      <pubDate>Mon, 05 Feb 2007 12:59:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937206#M762891</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-02-05T12:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937207#M762892</link>
      <description>&amp;gt;Clay: I was merely trying to point out that while the "typeset -i" ...&lt;BR /&gt;&lt;BR /&gt;Yes, I understood that but wanted to mention what use you could do with bases.</description>
      <pubDate>Mon, 05 Feb 2007 21:02:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937207#M762892</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-05T21:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: typeset usage</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937208#M762893</link>
      <description>Sangeeta,&lt;BR /&gt;you have had quite a few answers here.&lt;BR /&gt;&lt;BR /&gt;If this problem is resolved, could you please complete the thread by awarding points to helpful answers and summarising the solution for you.&lt;BR /&gt;&lt;BR /&gt;This will help resolution of similar problems in the future.</description>
      <pubDate>Wed, 07 Feb 2007 05:37:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/typeset-usage/m-p/3937208#M762893</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-02-07T05:37:28Z</dc:date>
    </item>
  </channel>
</rss>

