From 57cf9055d524e2ac79cbdc2de497af14a9124bad Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 23 Oct 2018 16:55:44 +0200 Subject: [PATCH] FAQ: Add pkg-config/splitting question Fixes #4855. --- doc_src/faq.hdr | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc_src/faq.hdr b/doc_src/faq.hdr index 96477099d..482c152d9 100644 --- a/doc_src/faq.hdr +++ b/doc_src/faq.hdr @@ -12,6 +12,7 @@ - How do I set my prompt? - How do I run a command from history? - How do I run a subcommand? The backtick doesn't work! +- My command (pkg-config) gives its output as a single long string? - How do I get the exit status of a command? - How do I set an environment variable for just one command? - Why doesn't `set -Ux` (exported universal variables) seem to work? @@ -81,6 +82,33 @@ for i in (ls) end \endfish +\section faq-pkg-config My command (pkg-config) gives its output as a single long string? + +Unlike other shells, fish splits command substitutions only on newlines, not spaces or tabs or the characters in $IFS. + +That means if you run + +\fish{cli-dark} +echo x(printf '%s ' a b c)x +\endfish + +It will print `xa b c x`. But if you do + +\fish{cli-dark} +echo x(printf '%s\n' a b c)x +\endfish + +it will print `xax xbx xcx`. + +In the overwhelming majority of cases, splitting on spaces is unwanted, so this is an improvement. + +However sometimes, especially with `pkg-config` and related tools, splitting on spaces is needed. + +In these cases use `string split " "` like: + +\fish{cli-dark} +g++ example_01.cpp (pkg-config --cflags --libs gtk+-2.0 | string split " ") +\endfish \section faq-exit-status How do I get the exit status of a command?