Re: Bash --- columns problem ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steven W. Orr wrote:
<snip>
: Why use grep or pr or any other shellout when you can just do it right 
: from within bash?
: 
: myRead()
: {
:     typeset line1, line2, line3
:     read line1
:     read line2
:     read line3
:     echo "$line1 $line2 $line3"
:     [[ -n "$line1" && -n "$line2" && -n "$line3" ]]
: }
: while myRead
: do
:     :
: done < /usr/share/dict/words 


I could be wrong, but to answer your question:

1) Because `pr --columns=3' is a whole lot easier to type than what you suggest

2) Because what you suggest has a bug, at least on my machine.
   When I run it, I get


==>./foo
./foo: line 3: typeset: `line1,': not a valid identifier
./foo: line 3: typeset: `line2,': not a valid identifier
./foo: line 3: typeset: `line1,': not a valid identifier
./foo: line 3: typeset: `line2,': not a valid identifier
./foo: line 3: typeset: `line1,': not a valid identifier
./foo: line 3: typeset: `line2,': not a valid identifier
./foo: line 3: typeset: `line1,': not a valid identifier

and so forth


3) Because your suggestion would give the opposite of what I would
   expect if I were asked to turn the following into three columns:

a
b
c
d
e
f
g
h
i
j
k
l

I would want:

a  e  i
b  f  j
c  g  k
d  h  l

Yours will give:

a  b  c
d  e  f
g  h  i
j  k  l

Dean


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux