Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

bash: read -a ARR

Posted on 2006-05-02
7
Medium Priority
?
1,044 Views
Last Modified: 2009-12-16
[raven@kruk tmp]$ read -a ARR < /etc/passwd
[raven@kruk tmp]$ echo ${ARR[0]}
root:x:0:0:root:/root:/bin/bash
[raven@kruk tmp]$ echo ${ARR[1]}

[raven@kruk tmp]$

I assure All of of You, there is more lines in /etc/passwd
Adding IFS="
"
before does nothing.
What i'm doing wrong?
0
Comment
Question by:ravenpl
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 16589064

Instead of 'read' uset this:

set -A ARR `cat /etc/passwd`
echo ${ARR[0]}
echo ${ARR[1]}
0
 
LVL 43

Author Comment

by:ravenpl
ID: 16589094
[raven@kruk ~]$ set -A ARR `cat /etc/passwd`
-bash: set: -A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]

[raven@kruk ~]$ bash --version
GNU bash, version 3.00.16(1)-release (i386-redhat-linux-gnu)
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 16589137

Ooops, yes -- It's ksh.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 400 total points
ID: 16589667

Ok, for bash try this:

ARR=(`cat /etc/passwd`)
echo ${ARR[0]}
echo ${ARR[1]}

0
 
LVL 43

Author Comment

by:ravenpl
ID: 16593646
That works - thanks. 100A points assured.

Does anyone knows why bash's read does not work?
If anybody would answer that, I'll give another 100pts.
0
 
LVL 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 400 total points
ID: 16594611
19:50:02$ help read
read: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
    One line is read from the standard input, or from file descriptor FD if the
    -u option is supplied, and the first word is assigned to the first NAME,

(rest of o/p deleted)

The key point here is that bash's help explicitly states that read reads *one line*, exactly as you found it did.
0
 
LVL 43

Author Comment

by:ravenpl
ID: 16594807
Looks like You right..
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question