Conversation
Format each argument as a json string and join on newline Split out quoting.hh from string_utils.hh. Also split options_strings.hh from string_utils.hh. This seemed less awkward than keeping the material in quoting.hh. Added `#include <algorithm>` to strings.hh. Without this compile failed on FreeBSD 14.1, clang version 18.1.5.
I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
|
@mawww wrote:
Following this suggestion I can do this: rather than I prefer the second version because it avoids extra parsing in shell, avoids having to put the potentially large content into command-line arguments, and is much clearer. The first approach was not obvious to me, and needed the |
This PR implements a new quoting option,
echo -quoting jsonas suggested in #3783. This option formats each argument as a json string and prints them joined by newlines. A simple use case is:This way large and list-valued outputs are easy to handle in external scripts without having to pass them in environment.
The implementation is not very complex, but does involve some minor refactoring,
splitting quoting.hhandoption_strings.hhout fromstring_utils.hh. While this could have been done with a split ofquoting.hhalone, it seemed to me less awkward to split them both. I followed the apparent conventions as I understand them, but would appreciate a review from a real C++ programmer, especially of the#includeupdates .Also
string.hhneeded#include <algorithm>to compile on FreeBSD 14.1, clang 18.1.5.