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: Peng Yu
Subject: Re: [Help-bash] How to print a bash variable in the most succinct way?
Date: Wed, 17 Aug 2016 08:10:26 -0500

On Tuesday, August 16, 2016, Chet Ramey <address@hidden> wrote:

> On 8/16/16 9:40 PM, Peng Yu wrote:
> >
> >
> > On Tuesday, August 16, 2016, Chet Ramey <address@hidden
> <javascript:;>
> > <mailto:address@hidden <javascript:;>>> wrote:
> >
> >     On 8/16/16 9:21 PM, Peng Yu wrote:
> >     > On Tue, Aug 16, 2016 at 8:13 PM, Chet Ramey <address@hidden
> <javascript:;>
> >     <javascript:;>> wrote:
> >     >> On 8/16/16 4:54 PM, Peng Yu wrote:
> >     >>> On Tue, Aug 16, 2016 at 2:56 PM, Chet Ramey <address@hidden
> <javascript:;>
> >     <javascript:;>> wrote:
> >     >>>> On 8/16/16 3:21 PM, Peng Yu wrote:
> >     >>>>
> >     >>>>>
> >     >>>>> How to only generate variables that are modifiable (i.e., not
> >     readonly)?
> >     >>>>
> >     >>>> Generate a list of all variables.  Generate a list of readonly
> >     variables.
> >     >>>
> >     >>> How to generate a list of the names of the readonly variables?
> >     >>> `readonly` will print both the names and their values. I will
> run into
> >     >>> the same problem when there are $'\n' in their values.
> >     >>
> >     >> Use the toolset.
> >     >>
> >     >> readonly -p | grep = | sed 's|^declare.*
> >     \([[:upper:][:lower:]_]*\)=.*$|\1|'
> >     >> readonly -p | awk '$0 ~ "declare.*" {print $3}' | sed
> >     >> 's|[^[:upper:][:lower:]_].*$||'
> >     >
> >     > These commands won't work robustly as shown below.
> >
> >     Then modify them.  You have to do some of the work yourself here.
> >
> >
> > It will requires a parser to parse the result if one wants it to robust.
> It
> > can require quite some work.
>
> A one-character change to the awk version of the command will work with
> bash-4.4.


Could you elaborate what you mean? Which one char change? What is the
difference between bash 4.4 and 4.3 that would help the solution of this
problem.

>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    address@hidden <javascript:;>
> http://cnswww.cns.cwru.edu/~chet/
>


-- 
Regards,
Peng


reply via email to

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