[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: |
Tue, 16 Aug 2016 20:21:20 -0500 |
On Tue, Aug 16, 2016 at 8:13 PM, Chet Ramey <address@hidden> wrote:
> On 8/16/16 4:54 PM, Peng Yu wrote:
>> On Tue, Aug 16, 2016 at 2:56 PM, Chet Ramey <address@hidden> 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.
~$ readonly x=($'a\nb' $'c\nd')
~$ readonly -p | grep = | sed 's|^declare.* \([[:upper:][:lower:]_]*\)=.*$|\1|'
BASHOPTS
BASH_VERSINFO
EUID
PPID
SHELLOPTS
UID
x
b" [1]="c
Another bash session.
~$ readonly z=($'a\ndeclare -a y=(')
~$ readonly -p | awk '$0 ~ "declare.*" {print $3}' | sed
's|[^[:upper:][:lower:]_].*$||'
BASHOPTS
BASHPID
BASH_VERSINFO
EUID
PPID
SHELLOPTS
UID
z
y
--
Regards,
Peng
- Re: [Help-bash] How to print a bash variable in the most succinct way?, (continued)
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chet Ramey, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Peng Yu, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chet Ramey, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Peng Yu, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Greg Wooledge, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Peng Yu, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Greg Wooledge, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chet Ramey, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Peng Yu, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chris F.A. Johnson, 2016/08/16
- Message not available
- Message not available
- Re: [Help-bash] How to print a bash variable in the most succinct way?,
Peng Yu <=
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chet Ramey, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Peng Yu, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chet Ramey, 2016/08/16
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Peng Yu, 2016/08/17
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Chet Ramey, 2016/08/17
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Eduardo A . Bustamante López, 2016/08/17
- Re: [Help-bash] How to print a bash variable in the most succinct way?, Greg Wooledge, 2016/08/17
Re: [Help-bash] How to print a bash variable in the most succinct way?, David Niklas, 2016/08/26