<?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: Incremental by 1 in the for loop in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397745#M681833</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Thanks, any ideas with 'for' loop?&lt;BR /&gt;&lt;BR /&gt;No, not with the shell.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Wed, 08 Apr 2009 14:05:24 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-04-08T14:05:24Z</dc:date>
    <item>
      <title>Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397742#M681830</link>
      <description>He,&lt;BR /&gt;&lt;BR /&gt;it is easy for 3 elements:&lt;BR /&gt;for i in 1 2 3; do echo $i; done&lt;BR /&gt;&lt;BR /&gt;How I can make it for 100 elements without listing all the numbers? Thanks in advance.&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Apr 2009 13:51:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397742#M681830</guid>
      <dc:creator>wojtek75</dc:creator>
      <dc:date>2009-04-08T13:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397743#M681831</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i N=1&lt;BR /&gt;while (( N &amp;lt;= 100 ))&lt;BR /&gt;do&lt;BR /&gt;    echo ${N}&lt;BR /&gt;    N=$N+1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 08 Apr 2009 13:55:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397743#M681831</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-08T13:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397744#M681832</link>
      <description>Thanks, any ideas with 'for' loop?</description>
      <pubDate>Wed, 08 Apr 2009 13:59:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397744#M681832</guid>
      <dc:creator>wojtek75</dc:creator>
      <dc:date>2009-04-08T13:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397745#M681833</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Thanks, any ideas with 'for' loop?&lt;BR /&gt;&lt;BR /&gt;No, not with the shell.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 08 Apr 2009 14:05:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397745#M681833</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-08T14:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397746#M681834</link>
      <description>Together with agreeing JRF's "not with `for`" view, I am under the impression that you are trying to do something with a vast number of files or similar. If this is the case, for directive can work for you, if you can come up with a regex (regular expression), covering all of these files. For example:&lt;BR /&gt;&lt;BR /&gt;for file in `ls -1 /home/mydir/data/IN*`&lt;BR /&gt;do&lt;BR /&gt;echo ${file}&lt;BR /&gt;cp ${file} /home/mydir/archive&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;if you are dealing with sequential numbering and do not want to write numbers one-by-one manually, you have no other choice than using the while construct, as 'for' directive does not work the same way in UNIX shells as it does on high level languages as BASIC.&lt;BR /&gt;&lt;BR /&gt;Hope this helps</description>
      <pubDate>Wed, 08 Apr 2009 14:27:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397746#M681834</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2009-04-08T14:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397747#M681835</link>
      <description>&lt;!--!*#--&gt;&amp;gt; Thanks, any ideas with 'for' loop?&lt;BR /&gt;&lt;BR /&gt;No matter how much you love your hammer,&lt;BR /&gt;sometimes a screwdriver is a better tool for&lt;BR /&gt;the job.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Perhaps you could "echo ${N}" into a&lt;BR /&gt;variable, and use that result in a "for"&lt;BR /&gt;statement.  (But that wouldn't make it the&lt;BR /&gt;right thing to do.)</description>
      <pubDate>Wed, 08 Apr 2009 14:30:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397747#M681835</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-04-08T14:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397748#M681836</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Steven makes a good point.  If you want a better "hammer" you need to look elsewhere.&lt;BR /&gt;&lt;BR /&gt;The 'sh-posix' manpages make it clear that a 'for' loop is the interation over a list unlike C's 'for' loop or even Perl's variations.  In Perl, for example, I could write:&lt;BR /&gt;&lt;BR /&gt;# perl -le 'for ($n=1;$n&amp;lt;=100;$n++) {print $n}'&lt;BR /&gt;&lt;BR /&gt;...using the C-syntax for 'for'.  However, I wouldn't do that when I could do:&lt;BR /&gt;&lt;BR /&gt;# perl -le 'print for 1..100'&lt;BR /&gt;&lt;BR /&gt;It's all about TIMTOWDI --- screwdrivers and hammers; but if all you have is a hammer, you have to use it as intended :-)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 08 Apr 2009 15:12:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397748#M681836</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-08T15:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Increment by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397749#M681837</link>
      <description>&lt;P&gt;&amp;gt;JRF: N=$N+1&lt;BR /&gt;&lt;BR /&gt;A typo, it should be: (( N = N + 1 )) or (( N += 1 ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Actually that initial assignment does work but you can't have spaces.)&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2012 08:27:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397749#M681837</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-05-28T08:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397750#M681838</link>
      <description>Hi,&lt;BR /&gt;to generate a range of &lt;BR /&gt;numbers for further use within a command pipe or &lt;BR /&gt;shell script. This can be done with some simple &lt;BR /&gt;sh-code:&lt;BR /&gt;&lt;BR /&gt;------------------------ CUT HERE ------------------&lt;BR /&gt;&lt;BR /&gt;#! /bin/sh&lt;BR /&gt;&lt;BR /&gt;# range - Generate of numbers.&lt;BR /&gt;&lt;BR /&gt;lo=$1&lt;BR /&gt;hi=$2&lt;BR /&gt;&lt;BR /&gt;while [ $lo -le $hi ]&lt;BR /&gt;do &lt;BR /&gt;  echo -n $lo " "&lt;BR /&gt;  lo=`expr $lo + 1`&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;------------------------ CUT HERE ------------------&lt;BR /&gt;&lt;BR /&gt;It can now be used a way like:&lt;BR /&gt;&lt;BR /&gt;for i in $(range 1 100); do &lt;SOME code=""&gt;; done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art&lt;/SOME&gt;</description>
      <pubDate>Thu, 09 Apr 2009 05:56:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397750#M681838</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2009-04-09T05:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397751#M681839</link>
      <description>To my mind it can be done.&lt;BR /&gt;&lt;BR /&gt;You generate the numbers in a file with &lt;BR /&gt;a while loop (see above), but output &amp;gt;$TMPFILE&lt;BR /&gt;&lt;BR /&gt;and then in your forloop you do&lt;BR /&gt;&lt;BR /&gt;for i in  $(cat $TIMPFILE)&lt;BR /&gt;do&lt;BR /&gt;typeset -i count&lt;BR /&gt;print $count&lt;BR /&gt;count=count+1&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Apr 2009 07:20:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397751#M681839</guid>
      <dc:creator>Frank de Vries</dc:creator>
      <dc:date>2009-04-09T07:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Increment by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397752#M681840</link>
      <description>&lt;!-- !*# --&gt;&lt;P&gt;&amp;gt;Frank: To my mind it can be done.&lt;BR /&gt;&lt;BR /&gt;Though in efficient, you could fix it as:&lt;BR /&gt;typeset -i count&lt;BR /&gt;for i in $(&amp;lt; $TMPFILE); do&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print $count&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (( count+=1 ))&lt;BR /&gt;done&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2012 08:25:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397752#M681840</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-05-28T08:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397753#M681841</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;As an encompassing remark, efficiency may not seem very measureable in small scripts operating on minute amounts of data.  Good practices there, however, lead to fast, scalable code that "thinks green".&lt;BR /&gt;&lt;BR /&gt;Using 'typeset -i' creates an integer variable that makes arithmetic faster.&lt;BR /&gt;&lt;BR /&gt;Using '(( N = N + 1 ))' to increment an integer by one lets the shell do the work without spawning a completely different process as when 'N=`expr $N + 1`' is used.&lt;BR /&gt;&lt;BR /&gt;Writing 'X=$(&amp;lt; $FILE)' instead of 'X=$(cat $FILE)' is a subtle but faster optimization for capturing the contents of a file into a variable.&lt;BR /&gt;&lt;BR /&gt;While, TMTOWTDI, there are fast and there are slow(er) paths to travel.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Apr 2009 11:21:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397753#M681841</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-09T11:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397754#M681842</link>
      <description>&lt;!--!*#--&gt;just a thought:&lt;BR /&gt;&lt;BR /&gt;if it would be a linux server you could just simply use the 'seq' command like this:&lt;BR /&gt;&lt;BR /&gt;for i in $(seq 1000)&lt;BR /&gt;do&lt;BR /&gt;     echo "This is the $i line."&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Apr 2009 11:27:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397754#M681842</guid>
      <dc:creator>Viktor Balogh</dc:creator>
      <dc:date>2009-04-09T11:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397755#M681843</link>
      <description>James, &lt;BR /&gt;Where can I find the documentation for the "typeset" command.&lt;BR /&gt;&lt;BR /&gt;I looked in man pages, typed "typeset -?" and "-h", looked in several books but still can't find it.&lt;BR /&gt;&lt;BR /&gt;RayB</description>
      <pubDate>Thu, 09 Apr 2009 11:50:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397755#M681843</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2009-04-09T11:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397756#M681844</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; James, Where can I find the documentation for the "typeset" command.&lt;BR /&gt;&lt;BR /&gt;The 'typeset' command is documented in shell manpages:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B3921-60631/sh-posix.1.html" target="_blank"&gt;http://docs.hp.com/en/B3921-60631/sh-posix.1.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Apr 2009 16:25:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397756#M681844</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-09T16:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397757#M681845</link>
      <description>&amp;gt;JRF: Using '(( N = N + 1 ))' to increment an integer by one lets the shell do the work&lt;BR /&gt;&lt;BR /&gt;Another reason to use ksh's (( )) is that it supports 64 bit integers and expr(1) only 32.</description>
      <pubDate>Fri, 10 Apr 2009 02:40:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397757#M681845</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-04-10T02:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Incremental by 1 in the for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397758#M681846</link>
      <description>Hi,&lt;BR /&gt;revised to be more efficient:&lt;BR /&gt;------------------------ CUT HERE ------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;# range - Generate of numbers.&lt;BR /&gt;typeset -i lo=$1&lt;BR /&gt;typeset -1 hi=$2&lt;BR /&gt;while [ $lo -le $hi ]&lt;BR /&gt;do &lt;BR /&gt;  echo -n $lo " "&lt;BR /&gt;  (( lo=lo+1 ))&lt;BR /&gt;done&lt;BR /&gt;------------------------ CUT HERE ------------------&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Fri, 10 Apr 2009 06:31:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/incremental-by-1-in-the-for-loop/m-p/4397758#M681846</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2009-04-10T06:31:48Z</dc:date>
    </item>
  </channel>
</rss>

