Difference between revisions of "Mapfile"
Jump to navigation
Jump to search
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{lowercase}} | {{lowercase}} | ||
+ | |||
+ | mapfile -t YourArrayName < <([[jq]] -r 'keys[]' yourfile.json) | ||
+ | mapfile -t YourArrayName < <([[jq]] yourfile.json) | ||
+ | |||
+ | <code>printf "%s\n" ${YourArrayName[@]}</code> | ||
<pre> | <pre> | ||
Line 35: | Line 40: | ||
not an indexed array. | not an indexed array. | ||
</pre> | </pre> | ||
+ | |||
+ | == Related == | ||
+ | * [[map]] | ||
== See also == | == See also == |
Latest revision as of 06:21, 15 March 2022
mapfile -t YourArrayName < <(jq -r 'keys[]' yourfile.json) mapfile -t YourArrayName < <(jq yourfile.json)
printf "%s\n" ${YourArrayName[@]}
mapfile: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array] Read lines from the standard input into an indexed array variable. Read lines from the standard input into the indexed array variable ARRAY, or from file descriptor FD if the -u option is supplied. The variable MAPFILE is the default ARRAY. Options: -d delim Use DELIM to terminate lines, instead of newline -n count Copy at most COUNT lines. If COUNT is 0, all lines are copied -O origin Begin assigning to ARRAY at index ORIGIN. The default index is 0 -s count Discard the first COUNT lines read -t Remove a trailing DELIM from each line read (default newline) -u fd Read lines from file descriptor FD instead of the standard input -C callback Evaluate CALLBACK each time QUANTUM lines are read -c quantum Specify the number of lines read between each call to CALLBACK Arguments: ARRAY Array variable name to use for file data If -C is supplied without -c, the default quantum is 5000. When CALLBACK is evaluated, it is supplied the index of the next array element to be assigned and the line to be assigned to that element as additional arguments. If not supplied with an explicit origin, mapfile will clear ARRAY before assigning to it. Exit Status: Returns success unless an invalid option is given or ARRAY is readonly or not an indexed array.
Related[edit]
See also[edit]
Bash [ -c ]
,alias
,&&
, Bash history, Autocompletion,set
,unset
,export
,.bash_aliases, .bashrc and .bash profile
,PS1
,echo
,brace expansion
, Function,shopt
,trap
,set -e
,source
,PATH
,complete
,disown
,.hushlogin
,.bashrc
,builtin
,eval
,set
,$PATH
,$HOME
,TZ
,.profile
,-e, -i
,Builtin (Bash)
,mapfile
,~
, return (Bash), for, until,declare, dirname, basename, functions.sh
, Bash arithmetic expansion,shift, bash --rcfile, readonly, $1, $@
Advertising: