0

I am using the WP-CLI for updating WooCommerce product_cat terms. When using wp wc product_cat get to retrieve individual fields, a line feed character (a0) seems to get inserted as leading character. Example:

$ echo "»"$(wp wc product_cat --user=4 get 44277 --field="description")"«"
» All widgets for A.-C.«

Another example - Note that the leading character is before the opening "

$ i1=$(wp wc product_cat --user=4 get 18869 --field="name" --format="json")
$ echo "format=json: »"$i1"«"
format=json: » "AEG"«

Additional information:

  • This happens for all fields
  • I verified that the added character is a0 by updating the field and checking in the database
  • Using --format didn't make a difference
  • Using --context didn't make a difference
  • I'm working on Linux Mint with Bash version 5.0.17(1).

Did I make a mistake somehwere in my syntaxis that inadvertently inserted this leading character? Or am I missing something in how WP-CLI or Bash works? Thanks in advance! Jeroen

Jeroen Strompf
  • 103
  • 1
  • 9
  • 1
    I'm not sure your conclusion that `wp` always inserts the LF is correct. First of all, you didn't quote the variables and command substitutions , therefore `echo`'s output contains a space instead of a LF. You said you updated a field in the database to check that the character is actually a LF, but doesn't that mean that some fields now contain a LF? In the json we can see that field `name` has no LF. The LF before `"` is still valid json. If you print the *same* field in plain format, do you still get a leading LF ? Use `wp .... | hexdump -c` to check this. – Socowi Aug 02 '21 at 11:03
  • 1
    Anyways, you can remove a leading LF using `wp ... | sed '1/^$/d'`. – Socowi Aug 02 '21 at 11:04

0 Answers0