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

Re: Structured (XML-like) input/output for shell apps?



Hi,

On Sat, Jun 11, 2005 at 07:40:10PM +0200, Olaf van der Spek wrote:

> Many shell apps/scripts output data in tables, for example ls -l, ps 
> aux, top, netstat, etc.
> At the moment, most of these apps use fixed-width columns with a 
> variable-width last-column.
> This results in (unnecessary) truncation, for example:
> Debian-  11918  0.0  0.1  4428 1464 ?        Ss   Jun05   0:00 
> /usr/sbin/exim4 -bd -q30m
> tcp 0 0 TC218-187-80-45.2:35589 bananensaft.inline.:www ESTABLISHEDproxy 
> 153239
> 
> Also, because the output isn't structured (in way easily readable by 
> machines), using the data in a script isn't (very) easy and is likely to 
> break due to strict dependency on the syntax.
> 
> Are there already any plans to solve these issues?

Yes. The commands you mention were designed for _human_ consumption. Do
not use them in scripts without good reasons. There are a lot of
commands to get well-formatted output without truncation. For example,
ls has a "-n" option for exactly this reason; stat(1) can be used
instead of "ls -l" to avoid clipping; ps has a _lot_ of formatting
options itself and all the data can be found under /proc in an easily
parseable format etc. You just have to select the right tool for the job
(that also includes using more powerful scripting languages if the task
is complicated).

> I was thinking, using structured output (and maybe input) in an XML-like 
> way would solve these and allow neat post-processing.

XML is just _terrible_ for human input/output.

Gabor

-- 
     ---------------------------------------------------------
     MTA SZTAKI Computer and Automation Research Institute
                Hungarian Academy of Sciences
     ---------------------------------------------------------



Reply to: