Issue
I am trying to install Operator Lifecycle Manager (OLM) — a tool to help manage the Operators running on your cluster — from the href="https://operatorhub.io/operator/gitlab-runner-operator" rel="nofollow noreferrer">official documentation, but I keep getting the error below. What could possibly be wrong?
This is the result from the command:
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.22.0/install.sh | bash -s v0.22.0
/bin/bash: line 2: $'\r': command not found
/bin/bash: line 3: $'\r': command not found
/bin/bash: line 5: $'\r': command not found
: invalid option6: set: -
set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
/bin/bash: line 7: $'\r': command not found
/bin/bash: line 9: $'\r': command not found
/bin/bash: line 60: syntax error: unexpected end of file
I've tried removing the existing curl and downloaded and installed another version but the issue has still persisted. Most solutions online are for Linux users and they all lead to Windows path settings and files issues.
I haven't found one tackling installing a file using curl
.
I'll gladly accept any help.
Solution
Using PowerShell on Windows, you must explicitly ensure that the stdout lines emitted by curl.exe
are separated with Unix-format LF-only newlines, \n
, when PowerShell passes them on to bash
, given that bash
, like other Unix shells, doesn't recognize Windows-format CRLF newlines, \r\n
:
The simplest way to avoid the problem is to call via cmd /c
:
cmd /c 'curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.22.0/install.sh | bash -s v0.22.0'
cmd.exe
's pipeline (|
) (as well as its redirection operator, >
), unlike PowerShell's (see below), acts as a raw byte conduit, so it simply streams whatever bytes curl.exe
outputs to the receiving bash
call, unaltered.
Fixing the problem on the PowerShell side requires more work, and is inherently slower:
(
(
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.22.0/install.sh
) -join "`n"
) + "`n" | bash -s v0.22.0
Note: `n
is a PowerShell escape sequence that produces a literal LF character, analogous to \n
in certain bash
contexts.
Note:
It is important to note that, as of PowerShell 7.2.x, passing raw bytes through the pipeline is not supported: external-program stdout output is invariably decoded into .NET strings on reading, and re-encoded based on the
$OutputEncoding
preference variable when writing to an(other) external program.- See this answer for more information, and GitHub issue #1908 for potential future support for raw byte streaming between external programs and on redirection to a file.
That is, PowerShell invariably interprets output from external programs, such as
curl.exe
, as text, and sends it line by line through the pipeline, as .NET string objects (the PowerShell pipeline in general conducts (.NET) objects).- Note that these lines (strings) do not have a trailing newline themselves; that is, the information about what specific newline sequences originally separated the lines is lost at that point (PowerShell itself recognizes CRLF and LF newlines interchangeably).
However, if the receiving command is also an external program, PowerShell adds a trailing platform-native newline to each line, which on Windows is a CRLF newline - this is what caused the problem.
By collecting the lines in an array up front, using
(...)
, they can be sent as a single, LF-separated multi-line string, using the-join
operator, as shown above.Note that PowerShell appends a trailing platform-native newline to this single, multi-line string too, but a stray
\r\n
at the very end of the input is in effect ignored bybash
, assuming that the last true input line ends in\n
, which is what the extra+ "`n"
at the end of the expression ensures.However, there are scenarios where this trailing CRLF newline does cause problems - see this answer for an example and workarounds via the platform-native shell.
Answered By - mklement0 Answer Checked By - Gilberto Lyons (WPSolving Admin)