[Techtalk] weirdness piping to a variable

Miriam English mim at miriam-english.org
Fri Sep 20 10:05:23 UTC 2013


Hi Daneel,

Thanks for your reply.

R. Daneel Olivaw wrote:

> I'm a bit late, as well :D

Me too again. :)

> some_var=$(command | command | command)

It is similar to what I usually do too, though I tend to use backticks. 
(I wonder if there is an advantage to one way rather than the other.)

But how much more logical and simple would it be if we could use 
something like:

command | command | command >>>some_var

We can already do the reverse:

echo "the quick brown fox" >tmpfile
a="tmpfile"
echo $a       # prints "tmpfile"
cat $a        # prints "the quick brown fox"
cat <<<$a     # prints "tmpfile" -- $a acts almost like a file

What was bothering me is how Unix/Linux treats variables differently 
from other things that we might store data into. One of the cool things 
about Unix/Linux is how files on different devices are treated the same 
way (except of course, that awful white elephant the CD/DVD device, 
where you can get data out the normal way, but storing data is nuts).

You can treat variables like files to some extent if you are getting 
stuff out of them, but not if storing it in them. This regularly trips 
people up, as evidenced by all the queries on the net about this... and 
not just by newbies.

Of course seasoned users will generally not see a problem, thinking it 
is pretty obvious that you only send the data from right to left when 
storing in a variable, but I think that's merely because they are used 
to it. Familiarity can lead to blindness. I've noticed this time and 
again in various areas of knowledge I've explored, and it is very 
apparent in many aspects of computing. It retards improvement because it 
makes it very difficult or even impossible for people who could fix 
problems to actually see that something could be improved.

What concerns me is the way unfamiliarity can allow someone to see many 
(perhaps hundreds) of these irregularities that form a great barrier to 
people who might wish to use Linux. Sadly, they are usually completely 
unnecessary, often being result of decisions that were a stopgap at the 
time (e.g. naming an important system configuration folder "etc"), or 
historical deadends that nobody could have foreseen (e.g. the 
conflicting, often opaque keystrokes of vi and emacs, vs more recent GUI 
standards). Many things do get fixed (the nice thing about opensource 
software), but many become entrenched and might never be undone.

Anyway, I know this particular irregularity with variables is only a 
tiny thing, and I'm sure it will remain long after I'm dead and gone. It 
isn't important in the larger scheme of things.

I'll shut up now and go back to doing things the same way again. :)

Thanks for letting me rattle on,

	- Miriam

-- 
If you don't have any failures then you're not trying hard enough.
  - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
-----
Website: http://miriam-english.org
Blogs:   http://miriam-e.dreamwidth.org
          http://miriam-e.livejournal.com




More information about the Techtalk mailing list