wp wc product_cat get – Remove leading whitespace?

Solution for wp wc product_cat get – Remove leading whitespace?
is Given Below:

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