mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 02:31:18 -03:00
Support "$(cmd)" command substitution without line splitting
This adds a hack to the parser. Given a command echo "x$()y z" we virtually insert double quotes before and after the command substitution, so the command internally looks like echo "x"$()"y z" This hack allows to reuse the existing logic for handling (recursive) command substitutions. This makes the quoting syntax more complex; external highlighters should consider adding this if possible. The upside (more Bash compatibility) seems worth it. Closes #159
This commit is contained in:
44
tests/checks/cmdsub.fish
Normal file
44
tests/checks/cmdsub.fish
Normal file
@@ -0,0 +1,44 @@
|
||||
#RUN: %fish %s
|
||||
|
||||
# Command substitution inside double quotes strips trailing newline.
|
||||
echo "a$(echo b)c"
|
||||
# CHECK: abc
|
||||
|
||||
# Nesting
|
||||
echo "$(echo "$(echo a)")"
|
||||
# CHECK: a
|
||||
echo "$(echo $(echo b))"
|
||||
# CHECK: b
|
||||
|
||||
echo "$(echo multiple).$(echo command).$(echo substitutions)"
|
||||
# CHECK: multiple.command.substitutions
|
||||
|
||||
test -n "$()" || echo "empty list is interpolated to empty string"
|
||||
# CHECK: empty list is interpolated to empty string
|
||||
|
||||
# Variables in command substitution output are not expanded.
|
||||
echo "$(echo \~ \$HOME)"
|
||||
# CHECK: ~ $HOME
|
||||
|
||||
echo "$(printf %s 'quoted command substitution multiline output
|
||||
line 2
|
||||
line 3
|
||||
')"
|
||||
# CHECK: quoted command substitution multiline output
|
||||
# CHECK: line 2
|
||||
# CHECK: line 3
|
||||
|
||||
echo trim any newlines "$(echo \n\n\n)" after cmdsub
|
||||
#CHECK: trim any newlines after cmdsub
|
||||
|
||||
echo i{1, (echo 2), "$(echo 3)"}
|
||||
# CHECK: i1 i2 i3
|
||||
|
||||
echo "$(echo index\nrange\nexpansion)[2]"
|
||||
#CHECK: range
|
||||
|
||||
echo "$(echo '"')"
|
||||
#CHECK: "
|
||||
|
||||
echo "$(echo $(echo 1) ())"
|
||||
#CHECK: 1
|
||||
Reference in New Issue
Block a user