You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 7, 2024. It is now read-only.
In our code, multiple stuffs that should be arrays (e.g. damn flags) are stored as strings, causing undesired results sometime, especially with param expansions.
Basic compatibility for data patterns can be achived in such way:
# Ultra-ugly varnames to avoid colisiontypeof(){ local ___t_{a,t,d,c}; for ___t_c;doread ___t_{a,t,d} <<<"$(declare -p "$___t_c")";echo"$___t_t";done; }
if [[ "$(typeof should_be_arr_but_was_not)"!=*a* ]];thenread -ra should_be_arr_but_was_not <<<"$should_be_arr_but_was_not"fi
However, commands cannot return arrays. All they can do are strings. Fortunately, we have \0:
foo_func(){
foriin a b c;doif [ -e"$i" ];then
magic_"$i"&&printf'%s\0'"$i"fi||breakdone
}
# http://mywiki.wooledge.org/BashFAQ/020unset a i
while IFS= read -rd '' file;do
a[i++]="$file"done<<(foo_func)
Or we will make all array-like outputting functions to put their output into a certain $_ab_tmp_arr, or use declare -n directives.
The text was updated successfully, but these errors were encountered:
In our code, multiple stuffs that should be arrays (e.g. damn flags) are stored as strings, causing undesired results sometime, especially with param expansions.
Basic compatibility for data patterns can be achived in such way:
However, commands cannot return arrays. All they can do are strings. Fortunately, we have
\0
:Or we will make all array-like outputting functions to put their output into a certain
$_ab_tmp_arr
, or usedeclare -n
directives.The text was updated successfully, but these errors were encountered: