Try โ€‚โ€‰HackMD

Quoting & Expansion in Nushell

Build 0.67.1 of nushell 3f93dc2f1dab82b7a80e20d5f54b08b33ff4563f

External commands

Test 1 with Git's echo.exe

Index Platform Test Result
1 Windows ^echo '**/*.json' wix/windows-terminal-profile.json
2 Windows ^echo "**/*.json" wix/windows-terminal-profile.json
3 Windows ^echo `**/*.json` .vs\ProjectSettings.json .vs\VSWorkspaceState.json .vscode\launch.json and all the other json flies
4 Windows ^echo **/*.json .vs\ProjectSettings.json .vs\VSWorkspaceState.json .vscode\launch.json and all the other json flies

Test 2 with Git's echo.exe but with backslash

Index Platform Test Result
5 Windows ^echo '**\*.json' ***.json
6 Windows ^echo "**\*.json" ***.json
7 Windows ^echo `**\*.json` .vs\ProjectSettings.json .vs\VSWorkspaceState.json .vscode\launch.json and all the other json flies
8 Windows ^echo **\*.json .vs\ProjectSettings.json .vs\VSWorkspaceState.json .vscode\launch.json and all the other json flies

Test 3 with cmd.exe /c built-in echo

forward slash or backward slash made no difference

Index Platform Test Result
9 Windows ^echo '**/*.json' '**/*.json'
10 Windows ^echo "**/*.json" \"**/*.json\"
11 Windows ^echo `**/*.json` `**/*.json`
12 Windows ^echo **/*.json **/*.json

Test 4 WSL2 Ubuntu's echo

> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

> which echo
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚ arg  โ”‚     path      โ”‚ built-in โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ echo โ”‚ /usr/bin/echo โ”‚ false    โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ # โ”‚ arg  โ”‚     path      โ”‚ built-in โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Index Platform Test Result
9 WSL2 ^echo '**/*.json' **/*.json
10 WSL2 ^echo "**/*.json" **/*.json
11 WSL2 ^echo `**/*.json` .vscode/settings.json crates/nu-command/assets/228_themes.json samples/wasm/package-lock.json samples/wasm/package.json target/.rustc_info.json and all the other json files
12 WSL2 ^echo **/*.json .vscode/settings.json crates/nu-command/assets/228_themes.json samples/wasm/package-lock.json samples/wasm/package.json target/.rustc_info.json and all the other json files

Test 5 with MacOS's built in echo

Index Platform Test Result
13 MacOS ^echo '**/*.json' **/*.json
14 MacOS ^echo "**/*.json" **/*.json
15 MacOS ^echo `**/*.json` .vscode/settings.json crates/nu-command/assets/228_themes.json samples/wasm/package-lock.json samples/wasm/package.json target/.rustc_info.json and all the other json files
16 MacOS ^echo **/*.json .vscode/settings.json crates/nu-command/assets/228_themes.json samples/wasm/package-lock.json samples/wasm/package.json target/.rustc_info.json and all the other json files

Test 6 quote argument with spaces

Index Platform Test Result
17 MacOS ^echo "โ€“name='xx' โ€“value='yy'" โ€“name='xx' โ€“value='yy'
18 MacOS ^echo 'โ€“name="xx" โ€“value="yy"' โ€“name="xx" โ€“value="yy"
19 Windows ^echo "โ€“name='xx' โ€“value='yy'" "โ€“name='xx' โ€“value='yy'" (failure)
20 Windows ^echo 'โ€“name="xx" โ€“value="yy"' 'โ€“name="xx" โ€“value="yy"' (failure)

But if the argument is defined as a variable, we don't need to quote them.

let argument = "--name='xx' --value='yy'"
Index Platform Test Result
21 MacOS ^echo $argument โ€“name='xx' โ€“value='yy'
22 Windows ^echo $argument โ€“name='xx' โ€“value='yy'
Index Platform Test Result
23 MacOS ^echo 'โ€“aa="bbbb"' โ€“aa="bbbb"
24 MacOS ^echo "โ€“aa='bbbb'" โ€“aa='bbbb'
25 MacOS ^echo โ€“aa="bbbb" โ€“aa="bbbb"
26 Windows ^echo 'โ€“aa="bbbb"' โ€“aa=\bbbb" (failure)
27 Windows ^echo "โ€“aa='bbbb'" โ€“aa=bbbb (failure)
28 Windows ^echo โ€“aa="bbbb" โ€“aa=bbbb (failure)

Test 7 - fzf with list of parameters

Setup

let-env FZF_DEFAULT_OPTS = '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"' let log_fmt_str = '%C(bold blue)%h%C(reset) - %C(cyan)%ad%C(reset) %C(yellow)%d%C(reset) %C(normal)%s%C(reset) %C(dim normal)[%an]%C(reset)'

Test 7.1 (preview with git show)

let selected_log_lines = ( git log [--format=format:($log_fmt_str) --date=short --color=always] | fzf [--ansi --multi --tiebreak=index --preview='git show --color=always --stat --patch {1}'] )

Result 7.1

  • Windows - Fails
  • MacOs - Fails

Test 7.2 (preview with git show - change quoting)

let selected_log_lines = ( git log [--format=format:($log_fmt_str) --date=short --color=always] | fzf [--ansi --multi --tiebreak=index "--preview=git show --color=always --stat --patch {1}"] )

Result 7.2

  • Windows - Succeeds
  • MacOs - Succeeds

Test 7.3 (preview with git show - remove list syntax)

let selected_log_lines = ( git log [--format=format:($log_fmt_str) --date=short --color=always] | fzf --ansi --multi --tiebreak=index --preview='git show --color=always --stat --patch {1}' )

Result 7.3

  • Windows - Succeeds
  • MacOs - Succeeds

Internal