On Wed, Mar 6, 2019 at 1:29 PM SanskritFritz <sanskritfr...@gmail.com>
wrote:

> Hi and thanks for your answer.
> Indeed this way it works, but I don't understand why, because when I
> test that expression this works:
> string match --regex ' diff .*::[^ ]+ 'aaa'$' "borg diff ::aaa aaa"
> and this doesn't because (commandline) can contain spaces:
> string match --regex ' diff .*::[^ ]+ 'aaa'$' borg diff ::aaa aaa
>

You seem to be under the misapprehension that fish behaves like POSIX
shells (e.g., bash) with respect to command substitution. That is, that the
output of `(commandline)` is split on whitespace. The POSIX equivalent,
`$(commandline)` does split on whitespace. But fish only splits (i.e.,
tokenizes) on newlines. So in fish, assuming the command line has a single
line, the output of `(commandline)` is equivalent to the double-quoted
string in your first example. There are various experiments you can do to
show this. For example:

set var (commandline)
set --show var

Note that this is also true for var expansion. Try this:

set var "borg diff ::aaa aaa"
string match --regex ' diff .*::[^ ]+ 'aaa'$' $var

 Notice that `$var` doesn't need to be enclosed in double-quotes. Unlike a
POSIX shell where you do need to quote the var expansion to keep it from
being split on $IFS.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to