I am trying to send the output of a wp-cli command to a slack webhook. WP-cli outputs tables with, in this case, plugin updates.
The command for this is:
$ wp plugin update --all --dry-run --format=table
The normal output is:
+-----------------------------------------+----------------+---------+----------------+
| name | status | version | update_version |
+-----------------------------------------+----------------+---------+----------------+
| aryo-activity-log | active-network | 2.6.1 | 2.7.0 |
| autoptimize | inactive | 2.8.3 | 2.8.4 |
+-----------------------------------------+----------------+---------+----------------+
But, when I put the table output into a variable, and echo the variable, all table markup has been stripped:
Available plugin updates: name status version update_version aryo-activity-log active-network 2.6.1 2.7.0 autoptimize inactive 2.8.3 2.8.4
The complete script is:
#!/bin/bash
updatesplugins=$(wp plugin update --all --dry-run --format=table)
echo $updatesplugins;
I am stuck at this point. Why does bash strip all these -, + and | characters? And how to keep this in its original state zo I can send the table/variable to, in this case, a slack webhook?
You can try redirecting the output to a text file instead of a variable. A variable usually stores data in a single line. Try something like this -
$(wp plugin update --all --dry-run --format=table) > updatesplugins.txt
cat updatesplugins.txt # or use it in some other command