Map bash table 输出到数组

Map bash table output to array

我如何将从列名中得到的值映射到一个数组中,以便稍后在我的 bash 脚本中使用?

+------------------------------+----------+-----------+---------+
| name                         | status   | update    | version |
+------------------------------+----------+-----------+---------+
| enable-jquery-migrate-helper | inactive | none      | 1.0.1   |
| gravityforms                 | inactive | none      | 2.4.17  |
| gutenberg                    | inactive | none      | 8.8.0   |
| redirection                  | inactive | none      | 4.8     |
| regenerate-thumbnails        | inactive | none      | 3.1.3   |
| safe-svg                     | inactive | none      | 1.9.9   |
| weglot                       | inactive | none      | 3.1.9   |
| wordpress-seo                | inactive | available | 14.8    |
+------------------------------+----------+-----------+---------+

我已经尝试了以下方法,但这只会在 table 中保存 headers 的名称:

IFS=$'\n' read -r -d '' -a my_array < <( wp plugin list  --status=inactive --skip-plugins  && printf '[=13=]' )

echo $my_array

 name status update version

检索到值后,我想遍历它们以将它们添加到数组中

如果您打算使用 shell 或 awk 脚本映射结果,最好使用 CSV 输出格式而不是默认的 table 格式:

wp plugin list --status=inactive --skip-plugins --format=csv

这将输出:

name,status,update,version
enable-jquery-migrate-helper,inactive,none,1.0.1
gravityforms,inactive,none,2.4.17 
gutenberg,inactive,none,8.8.0
redirection,inactive,none,4.8
regenerate-thumbnails,inactive none,3.1.3
safe-svg,inactive,none,1.9.9
weglot,inactive,none,3.1.9
wordpress-seo,inactive,available,14.8