Do I need to quote command substitutions?

$(echo foo bar) is indeed a command substitution. In this specific example, you don’t need double quotes because a variable assignment creates a “double quote context” for its right-hand side, so VAR=$(…) is equivalent to VAR=”$(…)”. In bash, you don’t need double quotes in export VAR=$(…) or declare VAR=$(…). But you do need the double … Read more

Write CSV To File Without Enclosures In PHP

The warnings about foregoing enclosures are valid, but you’ve said they don’t apply to your use-case. I’m wondering why you can’t just use something like this? <?php $fields = array( “field 1″,”field 2″,”field3hasNoSpaces” ); fputs(STDOUT, implode(‘,’, $fields).”\n”);

How to properly nest Bash backticks

Use $(commands) instead: $ echo “hello1-$(echo hello2-$(echo hello3-$(echo hello4)))” hello1-hello2-hello3-hello4 $(commands) does the same thing as backticks, but you can nest them. You may also be interested in Bash range expansions: echo hello{1..10} hello1 hello2 hello3 hello4 hello5 hello6 hello7 hello8 hello9 hello10

Powershell Formatting for a String

The reason your current attempt doesn’t work is that single-quoted (‘) string literals in PowerShell are verbatim strings – no attempt will be made at expanding subexpression pipelines or variable expressions. If you want an expandable string literal without having to escape all the double-quotes (“) contained in the string itself, use a here-string: $mynumber … Read more

Start-Process with PowerShell.exe exhibits different behavior with embedded single quotes and double quotes

js2010’s helpful answer is correct in that the use of Start-Process is incidental to your question and that the behavior is specific to PowerShell’s CLI (powershell.exe for Windows PowerShell, and pwsh for PowerShell (Core) 6+): On Windows[1], there are two layers of evaluation to consider: (a) The initial parsing of the command line into arguments. … Read more

Why do I get “/bin/sh: Argument list too long” when passing quoted arguments?

TL;DR A single argument must be shorter than MAX_ARG_STRLEN. Analysis According to this link: And as additional limit since 2.6.23, one argument must not be longer than MAX_ARG_STRLEN (131072). This might become relevant if you generate a long call like “sh -c ‘generated with long arguments’”. This is exactly the “problem” identified by the OP. … Read more

How do I call the PowerShell CLI robustly, with respect to character encoding, input and output streams, quoting and escaping?

PowerShell CLI fundamentals: PowerShell editions: The CLI of the legacy, bundled-with-Windows Windows PowerShell edition is powershell.exe, whereas that of the cross-platform, install-on-demand PowerShell (Core) 7+ edition is pwsh.exe (just pwsh on Unix-like platforms). Interactive use: By default, unless code to execute is specified (via -Command (-c) or -File (-f, see below), an interactive session is … Read more