mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-29 16:51:15 -03:00
Add string collect
The `string collect` subcommand behaves quite similarly in practice to `string split0 -m 0` in that it doesn't split its output, but it also takes an optional `--trim-newline` flag to trim a single trailing newline off of the output. See issue #159.
This commit is contained in:
@@ -6,6 +6,8 @@ string - manipulate strings
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
``string collect [(-n | --trim-newline)] [STRING...]``
|
||||
|
||||
``string escape [(-n | --no-quoted)] [--style=xxx] [STRING...]``
|
||||
|
||||
``string join [(-q | --quiet)] SEP [STRING...]``
|
||||
@@ -48,6 +50,17 @@ Most subcommands accept a ``-q`` or ``--quiet`` switch, which suppresses the usu
|
||||
|
||||
The following subcommands are available.
|
||||
|
||||
"collect" subcommand
|
||||
--------------------
|
||||
|
||||
``string collect [(-n | --trim-newline)] [STRING...]``
|
||||
|
||||
``string collect`` collects its input into a single output argument, without splitting the output when used in a command substitution. This is useful when trying to collect multiline output from another command into a variable. Exit status: 0 if any output argument is non-empty, or 1 otherwise.
|
||||
|
||||
If invoked with multiple arguments instead of input, ``string collect`` preserves each argument separately, where the number of output arguments is equal to the number of arguments given to ``string collect``.
|
||||
|
||||
``--trim-newline`` trims a single trailing newline off of each output argument. This is useful when collecting the output from another command as the trailing newline is frequently not desired.
|
||||
|
||||
"escape" and "unescape" subcommands
|
||||
-----------------------------------
|
||||
|
||||
@@ -329,6 +342,22 @@ Examples
|
||||
a1_20b2__c_E6_85_A1
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
>_ echo \"(echo one\ntwo\nthree | string collect)\"
|
||||
"one
|
||||
two
|
||||
three
|
||||
"
|
||||
|
||||
>_ echo \"(ech one\ntwo\nthree | string collect -n)\"
|
||||
"one
|
||||
two
|
||||
three"
|
||||
|
||||
|
||||
Match Glob Examples
|
||||
-------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user