Wp wc product attribute term get
$ wp help wc product_attribute_term get NAME wp wc product_attribute_term get DESCRIPTION Get a single item. SYNOPSIS wp wc product_attribute_term get <attribute_id> <id> [--id=<id>] [--attribute_id=<attribute_id>] [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>] OPTIONS <attribute_id> Attribute ID. <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--attribute_id=<attribute_id>] Unique identifier for the attribute of the terms. [--context=<context>] Scope under which the request is made; determines fields present in response. [--fields=<fields>] Limit response to specific fields. Defaults to all fields. [--field=<field>] Get the value of an individual field. [--format=<format>] Render response in a particular format. --- default: table options: - table - json - csv - ids - yaml - count - headers - body - envelope ---
Get a field without whitespace
Seems that this command always packages some CR/LF or other stuff in its output. Solution:
taxid=20 i=20208 # 1 - Not ok ######################################## # # Output includes CR/LF or something like that # echo " Old name: $(wp --user=4 wc product_attribute_term get $taxid $i --field=name --format=csv)" # 2 - Not OK ######################################## # tmp=$(wp --user=4 wc product_attribute_term get $taxid $i --field=name --format=csv) echo "Old name: $tmp" # 3 - Works ######################################## # # * Maybe this is why I use xargs often for processing the output of WP-CLI # commands # * This actually seems to be a legitimate use of xargs. It also reduces # multiple consecutive spaces to one: # https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable # wp --user=4 wc product_attribute_term get $taxid $i --field=name --format=csv | xargs # 4 - Not OK ######################################## # wp --user=4 wc product_attribute_term get $taxid $i --field=name --format=ids # 5 - Not OK ######################################## # wp --user=4 wc product_attribute_term get $taxid $i --field=id # 6 - Works - Best solution ######################################## # wp --user=4 wc product_attribute_term get $taxid $i --field=name --format=csv | grep . ]