I got the following error:
| cat << EOF > config.yaml
| ~
Missing file specification after redirection operator.`
my code in power shell is following
cat << EOF > config.yaml
serve:
proxy:
port: 4455 # run the proxy at port 4455
...
EOF
I am running in windows server
It looks like you're mistakenly trying to use
bashsyntax in PowerShell, namely a here-document.The PowerShell equivalent, with different syntax, is a here-string.[1]
The equivalent of the
bashstatement in your question in PowerShell is:Note:
Use
@'/'@instead as the delimiters to treat the content verbatim, i.e. to suppress string interpolation, so that$-prefixed tokens aren't interpreted as variable references, for instance. This is the equivalent of quoting (any part of) theEOFdelimiter inbash(e.g.cat << 'EOF' ...)Nothing may follow the opening delimiter (
@"/@') on the same line, and the closing delimiter ("@/'@) must be at the very start of the line - not even whitespace may precede it.PowerShell here-strings have no equivalent to the Bash here-document feature of stripping tab-based indentation from the content if the delimiter is prefixed with
-(e.g.cat << -EOF).Windows PowerShell caveats re character encoding:
>, the effective alias ofOut-File, defaults to "Unicode" (UTF-16LE) in Windows PowerShell (by contrast, in PowerShell (Core) (v6+) the consistent default, across all cmdlets, is BOM-less UTF-8).To control the character encoding, call
Out-File- or, with text input, preferably -Set-Contentwith the-Encodingparameter.E.g., replace
> config.yamlwith| Set-Content -Encoding Ascii config.yamlHowever, note that if you need UTF-8 encoding,
-Encoding utf8will invariably create a file with a BOM in Windows PowerShell (but not in PowerShell (Core), as noted); to avoid that, direct use of .NET APIs is needed - see this answer.[1] Not to be confused with
bash's here-strings,<<<"...", which are a single-line alternative to here-documents.