<?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: Do arrays work in the posix shell? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014796#M96618</link>
    <description>The set -A directive is quite nice as it can not only declare the array but assign some of all the values you need at one time. And the elements may be strings:&lt;BR /&gt; &lt;BR /&gt;set -A REASON \&lt;BR /&gt;"exceeded password lifetime" \&lt;BR /&gt;"exceeded last login time" \&lt;BR /&gt;"exceeded absolute account lifetime" \&lt;BR /&gt;"exceeded unsuccessful login attempts" \&lt;BR /&gt;"password required and a null password" \&lt;BR /&gt;"administrator lock" \&lt;BR /&gt;"password is a * (asterisk)"&lt;BR /&gt; &lt;BR /&gt;You can display all the defined elements with @ like this:&lt;BR /&gt; &lt;BR /&gt;echo "${REASON[@]}"&lt;BR /&gt; &lt;BR /&gt;or show the elements by number:&lt;BR /&gt; &lt;BR /&gt;for N in 0 1 2 3 4 5 6&lt;BR /&gt;do&lt;BR /&gt;echo "$N = \"${REASON[$N]}\""&lt;BR /&gt;done</description>
    <pubDate>Sun, 19 Nov 2006 19:34:18 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2006-11-19T19:34:18Z</dc:date>
    <item>
      <title>Do arrays work in the posix shell?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014793#M96615</link>
      <description>Trying to use arrays in the hpux posix shell and either I'm too dumb to interpret the manual page, or the shell's just broken in this respect.&lt;BR /&gt;&lt;BR /&gt;Tell me I'm dumb! :-)&lt;BR /&gt;&lt;BR /&gt;Could someone provide a working example of how to assign three values to one array variable and then reference them?&lt;BR /&gt;</description>
      <pubDate>Sun, 19 Nov 2006 16:18:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014793#M96615</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2006-11-19T16:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do arrays work in the posix shell?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014794#M96616</link>
      <description>Hi Trever:&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;# cat .sharray&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -A ARY this works for you&lt;BR /&gt;echo ${ARY[0]}&lt;BR /&gt;echo ${ARY[1]}&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;# ./sharray&lt;BR /&gt;this&lt;BR /&gt;works&lt;BR /&gt;&lt;BR /&gt;...Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 19 Nov 2006 16:55:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014794#M96616</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-11-19T16:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Do arrays work in the posix shell?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014795#M96617</link>
      <description>Thanks, James.&lt;BR /&gt;&lt;BR /&gt;You definitely did exactly what I asked, and now having seen that I realize I was very close in my own attempts, but I had forgotten the numbering started at 0, so when I was assigning using "set" and then referencing ${a[1]}, the shell was telling the truth when it claimed the variable wasn't set.  D'OH! :-)&lt;BR /&gt;</description>
      <pubDate>Sun, 19 Nov 2006 17:10:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014795#M96617</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2006-11-19T17:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Do arrays work in the posix shell?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014796#M96618</link>
      <description>The set -A directive is quite nice as it can not only declare the array but assign some of all the values you need at one time. And the elements may be strings:&lt;BR /&gt; &lt;BR /&gt;set -A REASON \&lt;BR /&gt;"exceeded password lifetime" \&lt;BR /&gt;"exceeded last login time" \&lt;BR /&gt;"exceeded absolute account lifetime" \&lt;BR /&gt;"exceeded unsuccessful login attempts" \&lt;BR /&gt;"password required and a null password" \&lt;BR /&gt;"administrator lock" \&lt;BR /&gt;"password is a * (asterisk)"&lt;BR /&gt; &lt;BR /&gt;You can display all the defined elements with @ like this:&lt;BR /&gt; &lt;BR /&gt;echo "${REASON[@]}"&lt;BR /&gt; &lt;BR /&gt;or show the elements by number:&lt;BR /&gt; &lt;BR /&gt;for N in 0 1 2 3 4 5 6&lt;BR /&gt;do&lt;BR /&gt;echo "$N = \"${REASON[$N]}\""&lt;BR /&gt;done</description>
      <pubDate>Sun, 19 Nov 2006 19:34:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014796#M96618</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2006-11-19T19:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Do arrays work in the posix shell?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014797#M96619</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;to make Bill's solution a little more general, you can loop through an array without explicitly naming the indices:&lt;BR /&gt;Change&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;for N in 0 1 2 3 4 5 6&lt;BR /&gt;do&lt;BR /&gt;echo "$N = \"${REASON[$N]}\""&lt;BR /&gt;done&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;To&lt;BR /&gt;&lt;BR /&gt;typeset -i N=-1&lt;BR /&gt;while [ N+=1 -lt ${#REASON[*]} ]&lt;BR /&gt;do print $N = \"${REASON[N]\"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Mon, 20 Nov 2006 05:04:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014797#M96619</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-11-20T05:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Do arrays work in the posix shell?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014798#M96620</link>
      <description>Thanks, guys.  I assigned 5 points each for the additional info, since James had already scored the 10.&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Nov 2006 08:17:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/do-arrays-work-in-the-posix-shell/m-p/5014798#M96620</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2006-11-20T08:17:56Z</dc:date>
    </item>
  </channel>
</rss>

