<?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: bash question in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5024999#M48144</link>
    <description>Should be something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;u[1]=`cut -d ":" -f 1 $RECORD`&lt;BR /&gt;v[1]=`cut -d ":" -f 3 $RECORD`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To print the value use:&lt;BR /&gt;&lt;BR /&gt;echo ${u[1]}&lt;BR /&gt;echo ${v[1]}&lt;BR /&gt;&lt;BR /&gt;You will need a While and a counter to process all lines of the passwd file.</description>
    <pubDate>Fri, 26 Jan 2007 11:18:38 GMT</pubDate>
    <dc:creator>Ivan Ferreira</dc:creator>
    <dc:date>2007-01-26T11:18:38Z</dc:date>
    <item>
      <title>bash question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5024998#M48143</link>
      <description>Hi Forum,&lt;BR /&gt;&lt;BR /&gt;What is an elegant way to assign multiple variables into an array in bash. For example,&lt;BR /&gt;Gien the two records below, I would like to see  the output &lt;BR /&gt;u[1]= named&lt;BR /&gt;u[2]= quagga&lt;BR /&gt;v[1]= 25&lt;BR /&gt;v[2]= 92&lt;BR /&gt;named:x:25:25:Named:/var/named:/sbin/nologin&lt;BR /&gt;quagga:x:92:92:Quaggasuite:/var/run/quagga:/sbin/nologin&lt;BR /&gt;&lt;BR /&gt;Thanks,</description>
      <pubDate>Fri, 26 Jan 2007 10:59:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5024998#M48143</guid>
      <dc:creator>George Liu_4</dc:creator>
      <dc:date>2007-01-26T10:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: bash question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5024999#M48144</link>
      <description>Should be something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;u[1]=`cut -d ":" -f 1 $RECORD`&lt;BR /&gt;v[1]=`cut -d ":" -f 3 $RECORD`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To print the value use:&lt;BR /&gt;&lt;BR /&gt;echo ${u[1]}&lt;BR /&gt;echo ${v[1]}&lt;BR /&gt;&lt;BR /&gt;You will need a While and a counter to process all lines of the passwd file.</description>
      <pubDate>Fri, 26 Jan 2007 11:18:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5024999#M48144</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2007-01-26T11:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: bash question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025000#M48145</link>
      <description>Ivan, Thanks. &lt;BR /&gt;Probably I didn't describe my problem clear. The entry number in the record file is unknown.  So using "while" statement is not a good option.&lt;BR /&gt;My goal is to use u[i] as a key to lookup its corresponding field v[i]. The lookup operations are used multiple times.</description>
      <pubDate>Fri, 26 Jan 2007 11:43:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025000#M48145</guid>
      <dc:creator>George Liu_4</dc:creator>
      <dc:date>2007-01-26T11:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: bash question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025001#M48146</link>
      <description>Why while is not an option? I was thinking in something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;i=1&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;  u[i]=`echo $LINE | cut -d ":" -f 1`&lt;BR /&gt;  v[i]=`echo $LINE | cut -d ":" -f 3`&lt;BR /&gt;  let "i++"&lt;BR /&gt;done  &amp;lt; /etc/passwd&lt;BR /&gt;&lt;BR /&gt;for n in `seq $i`&lt;BR /&gt;do&lt;BR /&gt;  echo "Showing the $n element"&lt;BR /&gt;  echo "Username: ${u[$n]}, USERID: ${v[$n]}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jan 2007 14:30:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025001#M48146</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2007-01-26T14:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: bash question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025002#M48147</link>
      <description>&lt;!--!*#--&gt;The Bash syntax for declaration and definition in one go would be&lt;BR /&gt;  &lt;BR /&gt;declare -a u=(named quagga) v=(25 92)&lt;BR /&gt; &lt;BR /&gt;But if you are reading the data from you passwd you could also parse entries from it and assign user and uid arrays in a loop like this&lt;BR /&gt; &lt;BR /&gt;declare -i i=0;while read l;do u[i]=$(echo $l|cut -d: -f1) v[i++]=$(echo $l|cut -d: -f3);done &amp;lt; /etc/passwd&lt;BR /&gt;&lt;BR /&gt;Please, note that index counting starts with 0.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Jan 2007 09:54:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025002#M48147</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-01-29T09:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: bash question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025003#M48148</link>
      <description>I am closing this thread. Thank you for your help.</description>
      <pubDate>Mon, 29 Jan 2007 10:33:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-question/m-p/5025003#M48148</guid>
      <dc:creator>George Liu_4</dc:creator>
      <dc:date>2007-01-29T10:33:17Z</dc:date>
    </item>
  </channel>
</rss>

