How to write a Drush script to retrieve data? I want to retrieve a field value by given nodes. Node has a field 'promo code'.

How can I retrieve imageurl value by giving 'promo code' field using a drush script?

What is the better way to do it?

I want to get data as a JSON or XML format for all the given nodes.
You can start checking the code of the Drush Entity module.


  With drush entity you can query the entity system available for Drupal
  8, 7 and (some of) 6.


And as Greg says you can use the Drushify module to start. 

In this links you can find good references:


How to Create Your Own Drush Command
How to write drush commands and hooks
Drush Integration for your modules