help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to print a bash variable in the most succinct way?


From: Marco Silva
Subject: Re: [Help-bash] How to print a bash variable in the most succinct way?
Date: Wed, 10 Aug 2016 11:04:56 -0300
User-agent: Sup/0.22.1

Excerpts from Greg Wooledge's message of 2016-08-10 08:40:24 -0400:
> Stop complaining that autogenerated code is less elegant than
> human-written code.  Write the code yourself if you don't like what a
> computer wrote for you.

You are wrong. As well as impolite. He is not complaining about
auto-generated code.

Actually, Mr. Yu has one good question about an idiom to construct
an array out of a list of values. Unfortunately, shell scripts
deals with many forms of lists, and arrays are really not a data
structure in shell. They were introduced to late, and they are clumsy to
retrieve values from.

You can compare:

set a b c; while [[ -n $1 ]]; do echo $1; shift; done

With

a=(a b c); i=0; while [[ $i -le 2 ]]; do echo ${a[$i]}; i=$(($i+1)); done

As you can see, arrays declaration is something cheap, just a list of
values separated by a $IFS . But, to retrieve it you must use a clumsy
syntax, which many authors avoid to use in favor of positional
parameters.

Hope it helps,

Cheers

-- 
Marco Arthur @ (M)arco Creatives



reply via email to

[Prev in Thread] Current Thread [Next in Thread]