[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: General Associative Array problem -- Was: UUID as Array Keys strange
From: |
Eduardo Bustamante |
Subject: |
Re: General Associative Array problem -- Was: UUID as Array Keys strangely not possible |
Date: |
Fri, 22 Feb 2019 08:17:34 -0800 |
On Fri, Feb 22, 2019 at 3:24 AM Robert White <rwhite@pobox.com> wrote:
(...)
> tail --lines=+3 /proc/partitions | grep -v ram |
> while read -a RECORD
> do
(...)
> eval EEEE[${INLINE[UUID]}]=boo
(...)
> done
>
> echo "EEEE Keys: " "${!EEEE[@]}" = "${EEEE[@]}"
> echo "FFFF Keys: " "${!FFFF[@]}" = "${FFFF[@]}"
> echo "GGGG Keys: " "${!GGGG[@]}" = "${GGGG[@]}"
The `while' loop executes in a subshell and you're not using
`lastpipe'. See: https://mywiki.wooledge.org/BashFAQ/024
As a general recommendation: when submitting bug reports, try to
simplify things as much as possible, e.g.:
* Replace the `blkid' command invokation with a `printf' (not everyone
has the same block devices, nor runs Linux)
* Replace `/proc/partitions' with a copy of its contents (again, not
everyone has the same files in their systems, makes it impossible to
reproduce what you're experiencing)
* Remove the FFFF and GGGG arrays, we only need a sample case to
understand what's going on, not three
* Remove the sed commands, you're going to be using static values
(`printf') anyways
* Does the `set -f' at the top of the file have any effect in the
outcome in this particular case? no? then remove it
* I think you get the idea.
Just to help you understand my perspective, this is what I see when I
try to troubleshoot your script (a bunch of errors), that doesn't
really help me help you:
dualbus@system76-pc:~$ shellcheck foo.sh
In foo.sh line 12:
function testfunc() {
^-- SC1009: The mentioned syntax error was in this function.
^-- SC1073: Couldn't parse this brace group. Fix
to allow more checks.
In foo.sh line 13:
eval INFUNC=( $( blkid /dev/${RECORD[3]} -o export | sed -e 's;\\
^-- SC1036: '(' is invalid here. Did you forget to escape it?
^-- SC1056: Expected a '}'. If you have one, try a ; or
\n in front of it.
^-- SC1072: Missing '}'. Fix any mentioned problems and
try again.
^-- SC1098: Quote/escape special characters when using
eval, e.g. eval "a=(b)".
dualbus@system76-pc:~$ ./foo.sh
Trying /dev/nvme0n1
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/nvme0n1p1
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/nvme0n1p2
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/nvme0n1p3
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/sda
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/sda1
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/sdb
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/sdb1
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
Trying /dev/sdb2
./foo.sh: line 14: blkid: command not found
sed: -e expression #1, char 4: unterminated `s' command
Trying: FFFF+=( []=boo )
./foo.sh: line 16: []=boo: bad array subscript
./foo.sh: line 26: blkid: command not found
sed: option requires an argument -- 'e'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate
consider files as separate rather than as a single,
continuous long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
./foo.sh: line 27: s;\(.*\)=;[\1]=;: command not found
INLINE Keys: =
INFUNC Keys: =
EEEE Keys: =
FFFF Keys: =
GGGG Keys: =