help-bash
[Top][All Lists]
Advanced

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

Parameter expansion, variables with prefix


From: Wiley Young
Subject: Parameter expansion, variables with prefix
Date: Thu, 26 Sep 2024 03:16:15 -0700

 Hi all,

>From the man page:

       "${!prefix*}
       "${!prefix@}
              "Names matching prefix. Expands to the names of variables
whose names begin with prefix, separated by the first character of the IFS
special variable. When @ is used and the expansion appears within double
quotes, each variable name expands to a separate word."

Do arrays / variables that are defined but empty print using this parameter
expansion?

Arrays:

liveuser@fedora:~$ declare -p | grep row
declare -- _="row_rem"
declare -- all_rows="6"
declare -- full_rows="5"
declare -- part_rows="1"
declare -a row0
declare -a row1
declare -a row2
declare -a row3
declare -a row4
declare -a row5
declare -a row_indx=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")
declare -- row_rem="6"
liveuser@fedora:~$ echo "${!row@}"
row_indx row_rem
liveuser@fedora:~$ echo "${!row*}"
row_indx row_rem
liveuser@fedora:~$ row5+=(x)
liveuser@fedora:~$ echo "${!row@}"
row5 row_indx row_rem
liveuser@fedora:~$

Variables:

~ $ declare col{0..5}
~ $ echo "${!col@}"

~ $ declare -p | grep -i col
declare -x COLORTERM="truecolor"
declare -- COLUMNS="37"
declare -x TERM="xterm-256color"
declare -- col0
declare -- col1
declare -- col2
declare -- col3
declare -- col4
declare -- col5
~ $

The arrays row{0..5} appear to be "variables whose names begin with
prefix," but when they don't have any elements assigned to them, they
aren't printing.

??
Wiley


reply via email to

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