Posts

Showing posts with the label echo

Get WordPress Multisite blog_id by blog's path using wp-cli

You have a csv file has this format (mycsv.csv): path,some_field somepath,some_value anotherpath,another_value ... and you want to get the blog_ids of those path(s). This following bash shell will help you to get blog_ids by taking advantages of wp-cli, get_blogid_from_url.sh: $ chmod +x get_blogid_from_url.sh $ ./get_blogid_from_url.sh mycsv.csv myblog.com /wordpress/path > result.csv The result will be something like: 546,myblog.com/somepath/ 456,myblog.com/anotherpath/ ...

Echo new line in bash shell

When echoing strings with new line character ("\n") you want the shell translates it for you (actually displaying text in new line not just the character), you can do as following: A string: mystr="Good morning.\nHow are you?\nI'm fine." echo -e "$mystr" And the result will be: Good morning. How are you? I'm fine. Result of a command: sites=$(wp site list --allow-root --path=/var/www/ --fields=blog_id,url --format=csv) echo "$sites" Note that quoting (") does matter to preserve multi-line values. the result will be something like this: 566,myblog.com/somepath/ 677,myblog.com/anotherpath/ ... Reference:   http://stackoverflow.com/questions/8467424/echo-new-line-in-bash-prints-literal-n