Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest RVM breaks on OSX #4618

Closed
clive-devops opened this issue Feb 17, 2019 · 56 comments · Fixed by #4711
Closed

Update to latest RVM breaks on OSX #4618

clive-devops opened this issue Feb 17, 2019 · 56 comments · Fixed by #4711
Assignees
Milestone

Comments

@clive-devops
Copy link

clive-devops commented Feb 17, 2019

After doing a rvm get master RVM no longer activated when I enter any ruby directory, instead I get failures as follows:

% cd my-project
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
(eval):1: command not found: cat
(eval):1: command not found: cat

The issue appears to be in scripts/functions/utility around lines 60-67:

  if
    [[ "$PATH" == *"//"* || "$PATH" == *"/:"* ]]
  then
    if [[ "${_system_type}" = "Darwin" ]]
    then PATH="$(\sed -E -e 's#/+#/#g' -e 's#/:#:#' <<<$PATH)"
    else PATH="$(\sed -r -e 's#/+#/#g' -e 's#/:#:#' <<<$PATH)"
    fi
  fi

When entering this code ${_system_type} is blank and Darwin is therefore misdetected.

@havenwood
Copy link
Member

Are you on macOS Mojave 10.14.3 (18D42)?

$_system_type should be Darwin, but in the case of no match it'll be unknown not blank.

@clive-devops
Copy link
Author

clive-devops commented Feb 19, 2019

I understand what it should be, I agree, however I edited the installed script and injected an "echo" to check what it is at the time it's executing that line of code and when it gets to that point, it's definitely blank.

I am currently on Mojave 10.14.2

I edited as follows:

  if
    [[ "$PATH" == *"//"* || "$PATH" == *"/:"* ]]
  then
    echo "_system_type: ##${_system_type}##" # DEBUG ECHO
    if [[ "${_system_type}" = "Darwin" ]]
    then PATH="$(\sed -E -e 's#/+#/#g' -e 's#/:#:#' <<<$PATH)"
    else PATH="$(\sed -r -e 's#/+#/#g' -e 's#/:#:#' <<<$PATH)"
    fi
  fi

Output as follows:

% cd my-project
_system_type: ####
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

@clive-devops
Copy link
Author

It does not appear that __rvm_detect_system is even being executed when I switch folders.

@pkuczynski
Copy link
Member

pkuczynski commented Feb 19, 2019

Could you please run rvm info and command uname and send us the output?

@clive-devops
Copy link
Author

rvm info

ruby-2.3.1:

  system:
    uname:        "Darwin clive-osx 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64"
    name:         "OSX"
    version:      "10.14"
    architecture: "x86_64"
    bash:         "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)"
    zsh:          "/usr/local/bin/zsh => zsh 5.6.2 (x86_64-apple-darwin18.2.0)"
    remote_path:  "osx/10.14/x86_64"
    xcode:        "10.1"

  rvm:
    version:      "1.29.7-next (master)"
    updated:      "1 day 15 hours 57 minutes 59 seconds ago"
    path:         "/Users/clivec/.rvm"
    autolibs:     "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."

  ruby:
    interpreter:  "ruby"
    version:      "2.3.1p112"
    date:         "2016-04-26"
    platform:     "x86_64-darwin17"
    patchlevel:   "2016-04-26 revision 54768"
    full_version: "ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin17]"

  homes:
    gem:          "/Users/clivec/.rvm/gems/ruby-2.3.1"
    ruby:         "/Users/clivec/.rvm/rubies/ruby-2.3.1"

  binaries:
    ruby:         "/Users/clivec/.rvm/rubies/ruby-2.3.1/bin/ruby"
    irb:          "/Users/clivec/.rvm/rubies/ruby-2.3.1/bin/irb"
    gem:          "/Users/clivec/.rvm/rubies/ruby-2.3.1/bin/gem"
    rake:         "/Users/clivec/.rvm/rubies/ruby-2.3.1/bin/rake"

  environment:
    PATH:         "/Users/clivec/.rvm/gems/ruby-2.3.1/bin:/Users/clivec/.rvm/gems/ruby-2.3.1@global/bin:/Users/clivec/.rvm/rubies/ruby-2.3.1/bin:/usr/local/heroku/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/clivec/bin:/Users/clivec/bin_Darwin-x86_64:/opt/cegcc/bin:/opt/mingw32ce/bin:/usr/lib/ccache:/var/lib/gems/1.9.1/bin:/opt/daf/bin:/opt/android/sdk/platform-tools:/opt/android/sdk/tools:/usr/local/lib/android-sdk-linux/tools:/usr/local/lib/android-sdk-linux/platform-tools:/var/lib/gems/1.8/bin:/usr/local/opt/go/libexec/bin:/Applications/VirtualBox.app/Contents/MacOS/:/Users/clivec/.rvm/bin"
    GEM_HOME:     "/Users/clivec/.rvm/gems/ruby-2.3.1"
    GEM_PATH:     "/Users/clivec/.rvm/gems/ruby-2.3.1:/Users/clivec/.rvm/gems/ruby-2.3.1@global"
    MY_RUBY_HOME: "/Users/clivec/.rvm/rubies/ruby-2.3.1"
    IRBRC:        "/Users/clivec/.rvm/rubies/ruby-2.3.1/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

uname

Darwin

uname -a

Darwin clive-osx 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

@pkuczynski
Copy link
Member

So definitely your system is recognized correctly. Can you check which cat?

@clive-devops
Copy link
Author

% which cat
/bin/cat

@pkuczynski
Copy link
Member

Could you run rvm get branch /fix-sed-darwin and try again?

@pkuczynski pkuczynski added the bug label Feb 19, 2019
@pkuczynski pkuczynski added this to the rvm-1.29.8 milestone Feb 19, 2019
@pkuczynski pkuczynski self-assigned this Feb 19, 2019
@clive-devops
Copy link
Author

I have managed to generate a traceback. In case this is useful to you, unfortunately line numbers in scripts/functions/utility will be offset by about +41 lines inside __rvm_remove_from_path

Traceback (last called is first):
     __rvm_remove_rvm_from_path() in /Users/clivec/.rvm/scripts/functions/env:2
     __rvm_use_common() in /Users/clivec/.rvm/scripts/functions/selector:5
     __rvm_use() in /Users/clivec/.rvm/scripts/functions/selector:10
     __rvm_load_project_config() in /Users/clivec/.rvm/scripts/functions/rvmrc_project:151
     __rvm_conditionally_do_with_env() in /Users/clivec/.rvm/scripts/functions/environment:3
     __rvm_project_rvmrc() in /Users/clivec/.rvm/scripts/functions/rvmrc_project:-268
     __rvm_cd_functions_set() in /Users/clivec/.rvm/scripts/cd:-457
     __zsh_like_cd() in /Users/clivec/.rvm/scripts/extras/bash_zsh_support/chpwd/function.sh:8
     cd() in /Users/clivec/.rvm/scripts/cd:0
bash: _system_type: unbound variable

@clive-devops
Copy link
Author

Unfortunately rvm get branch /fix-sed-darwin did not help with the issue :(

@pkuczynski
Copy link
Member

Do you have rvmrc in this project folder? If so, can I see it?

@clive-devops
Copy link
Author

I do not have an rvmrc in the project folder, I only have a .rvmrc in my home, as follows:

% cat ~/.rvmrc 
rvm_autoupdate_flag=2
rvm_autoupdate_flag=9
rvm_autoupdate_flag=0

@pkuczynski
Copy link
Member

You should have only one entry there :) Don't think this is related to this issue, but can you try?

@clive-devops
Copy link
Author

I tried that, without any change. At least now it's clean for the future.

@clive-devops
Copy link
Author

clive-devops commented Feb 19, 2019

I think I have a lead on the problem.
I edited my ~/.zshrc last line which used to look like this:

export PATH="$PATH:$HOME/.rvm/bin"

to rather look like this

export PATH="$HOME/.rvm/bin:$PATH"

... which seems to have fixed the issue. Something in my PATH appears to be breaking RVM I'm still looking into it to determine exactly what.

@pkuczynski
Copy link
Member

I don't see a difference between those two examples?

@clive-devops
Copy link
Author

Apologies, I fixed the examples above.
It looks like (at a guess) conflicting ruby versions due to system (non rvm) ruby installs, or something similarly strange. I'm happy to just include RVM at the beginning of my path rather than the end.

For fun, here's an ugly one-liner that identifies any $PATH duplicate executables thrown together to try figure out where things were going wrong here:

a={};ENV['PATH'].split(':').map{|n|Dir["#{n}/*"].map{|fp|File.basename(fp)}.map{|p|a[p]||=[];a[p] << n}};Hash[a.keys.select{|k|a[k].size > 1}.map{|k|[k,a[k]]}]

@clive-devops
Copy link
Author

clive-devops commented Feb 19, 2019

It appears I pre-emptively closed this.
This issue rears it's head again, after I changed the path order, if I do the following:

% cd my-project    #no error
% cd ..
% cd my-project
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

@clive-devops clive-devops reopened this Feb 19, 2019
@mpapis
Copy link
Member

mpapis commented Feb 19, 2019

@clive-hetzner could you add echo $PATH ; which -a sed to all the steps?

@zeninfinity
Copy link

I am experiencing this issue as well.

$ ls
repo
$ echo $PATH
/Users/user/.rvm/gems/ruby-2.4.2/bin:/Users/user/.rvm/gems/ruby-2.4.2@global/bin:/Users/user/.rvm/rubies/ruby-2.4.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/user/.rvm/gems/ruby-2.4.2/bin:/Users/user/.rvm/gems/ruby-2.4.2@global/bin:/Users/user/.rvm/rubies/ruby-2.4.2/bin:/Users/user/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/bin/:~/git/repo/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/Users/user/.rvm/bin
$ cd repo
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
-bash: cat: command not found
-bash: cat: command not found
-bash: sed: command not found
$ echo $PATH
/Users/user/.rvm/gems/ruby-2.4.2/bin:/Users/user/.rvm/gems/ruby-2.4.2@global/bin:/Users/user/.rvm/rubies/ruby-2.4.2/bin:/Users/user/.rvm/bin:
-bash: sed: command not found
$

I don't know a lot about this but it seems rvm, when cd'ing into a repo is creating a new path but not inheriting the old $PATH.

@zeninfinity
Copy link

More info:

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.

I can't really put my whole ~/.bash_profile here but I did attempt to declare the PATH variable before and after this line but it did not fix the PATH:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

But when I remove ^ line from my .bash_profile I get no errors....though that renders rvm useless as my which ruby ends up back to /usr/bin/ruby.

@pkuczynski
Copy link
Member

Could you run rvm get branch /fix-sed-darwin and try again?

@clive-devops
Copy link
Author

@danmayer this is 100% exactly what I'm experiencing myself. System detection is simply never being called, however the replies I keep getting from the devs ask about sed version.

See my full traceback showing it's unset, on this comment above: #4618 (comment)

@danmayer
Copy link

yes I agree it is about system detection the sed issue is only a secondary side effect. Thanks for posting all you did as I googled and debugged it from your comments @clive-hetzner ;)

@clive-devops
Copy link
Author

I have created a Dockerfile which fakes uname identification as OSX Darwin within an Ubuntu Dockerfile and shows where and how things are going wrong. There are three things required under normal circumstances in order to trigger this bug:

  1. Be on OSX
  2. Be using zsh
  3. Have a PATH which contains a forward-slash at the end of any individual element within it

All three of the above required "triggers" are setup within the attached Dockerfile.

Building the Dockerfile will not only set up the pre-conditions but also execute the failure during the last part of it's build, showing the sudden change in sed behaviour due to system detection failing, see the following screenshot which shows the Dockerfile build and the sudden change in arguments:

image

You can be execute and test this out yourselves simply by putting the attached Dockerfile in a folder by itself and running: docker build ./

Dockerfile.gz

Here's the full content of the Dockerfile, verbatim:

FROM ubuntu:18.04

# Setup base system with a tester user

RUN \
  apt-get update \
  && apt-get install -y sudo zsh \
  && useradd -ms /usr/bin/zsh tester \
  && usermod -aG sudo tester \
  && echo "tester ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/tester \
  && chmod 0440 /etc/sudoers.d/tester \
  && rm -rf /var/lib/apt/lists/*

USER tester
WORKDIR /home/tester

# Install RVM
#   XXX: From this point on the RUN lines are atomic for easier debugging

ARG CACHEBUST=0

ENV RVM_BUILD_PACKAGES="patch gawk g++ gcc autoconf automake bison libc6-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool libyaml-dev make patch pkg-config sqlite3 zlib1g-dev libgmp-dev libreadline-dev libssl-dev"

RUN sudo apt-get update && sudo apt-get install -y curl ${RVM_BUILD_PACKAGES}

#   XXX: RVM's checking of the gpg keys from the keyserver seems to fail 4 out
#        of 5 times, just retry if you hit that error until it succeeds at
#        which point it will continue from where it left off.
#        :: gpg: keyserver receive failed: Cannot assign requested address
RUN \
  gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \
  && curl -sSL https://get.rvm.io | bash -s stable --ruby

# Install an alternate Ruby version, to switch to, for testing
ARG PROJECT_RUBY_VERSION=2.5.1

RUN [ "/bin/bash", "-cl", "rvm install ${PROJECT_RUBY_VERSION}" ]

# Create a project to test with

RUN \
  mkdir project \
  && echo "ruby-${PROJECT_RUBY_VERSION}" > project/.ruby-version

# Fake OSX

RUN \
  true \
  && sudo mv /bin/uname /bin/uname~ \
  && echo "#!/bin/bash\necho \"%DEBUG% uname \$@\" 1>&2\n/bin/uname~ \"\$@\"|/bin/sed~ 's/^Linux/Darwin/g'" | sudo tee /bin/uname \
  && sudo chmod +x /bin/uname \
  && sudo mv /bin/sed /bin/sed~ \
  && echo "#!/bin/bash\necho \"%DEBUG% sed \$@\" 1>&2\n/bin/sed~ \"\$@\"" | sudo tee /bin/sed \
  && sudo chmod +x /bin/sed \
  && echo "#!/bin/bash\necho \"%DEBUG% sw_vers \$@\" 1>&2\necho \"10.14.4\"" | sudo tee /bin/sw_vers \
  && sudo chmod +x /bin/sw_vers

# Setup a PATH structure that'll trigger the sed call that's happening without
# _rvm_detect_sytem having been called

RUN echo "export PATH=$HOME/bin/:$PATH" >> $HOME/.zshenv

# Show that system detection works and detects "Darwin"

RUN [ "/usr/bin/zsh", "-cl", "__rvm_detect_system && echo \"\n\n%RESULT% Detected System: ${_system_type}\n\n\" 1>&2" ]

# Show the failure, how it's still passing '-r' into sed when a path is wrong

RUN [ "/usr/bin/zsh", "-cl", "echo 'Look at the last %DEBUG% line below, after this -- notice how suddenly \"-r\" is being passed to sed instead of \"-n\" ...' && cd project && echo 'And now we will trigger it again ...' && export PATH=$HOME/bin/:$PATH && cd .." ]

# Done, have some zsh
CMD /usr/bin/zsh --login

@danmayer
Copy link

Wow, great work @clive-hetzner amazing simple small reproducible version of the issue. Should make it easier to fix. Thanks, for the work on this.

I was on zsh, of course ;)

@clive-devops
Copy link
Author

I was on zsh, of course ;)

As if there's anything else ;) - yea I'm hoping this helps find the issue itself, it's been quite frustrating to me and some of the others on my team. I wish I knew more about rvm's internal mechanics to try isolate exactly where/how - so I've helped as far as I could.

@clive-devops
Copy link
Author

@pkuczynski (cc: @danmayer ) it appears this bug has been here a long time, however it was hidden until this fix d105f0b

Reverting that change, on my system, "fixes" the issue (hides it again).

@s22su
Copy link

s22su commented May 23, 2019

@pkuczynski (cc: @danmayer ) it appears this bug has been here a long time, however it was hidden until this fix d105f0b

Reverting that change, on my system, "fixes" the issue (hides it again).

Commenting out line 299 in ~/.rvm/scripts/functions/environment is the temporary fix right now until it is fixed properly.

@bryantgtx
Copy link

If it helps, I ran into this going into a directory with a .ruby-version file. If I remove that file, no problems. If I rvm use <version> before going in, no problems (and I can go in and out to my heart's content). This is on Mojave 10.14.5, rvm v1.29.7-next.

@ZevEisenberg
Copy link

+1 seeing the exact same issue. You can see how just cding into a folder with a .ruby-version file changes $PATH, and it stays broken even when I cd back to ~:

~ $ echo $PATH
/Users/igeek/.rvm/gems/ruby-2.5.3/bin:/Users/igeek/.rvm/gems/ruby-2.5.3@global/bin:/Users/igeek/.rvm/rubies/ruby-2.5.3/bin:/usr/local/sbin:/Applications/Sketch.app/Contents/Resources/sketchtool/bin/:/Users/igeek/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/opt/X11/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin
~ $ cd Projects/Siteswap  
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
(eval):1: command not found: cat
(eval):1: command not found: cat
~/Projects/Siteswap $ echo $PATH
/Users/igeek/.rvm/gems/ruby-2.5.3/bin:/Users/igeek/.rvm/gems/ruby-2.5.3@global/bin:/Users/igeek/.rvm/rubies/ruby-2.5.3/bin:/Users/igeek/.rvm/bin:
~/Projects/Siteswap $ cd                  
(eval):1: command not found: cat
(eval):1: command not found: cat
~ $ echo $PATH
/Users/igeek/.rvm/gems/ruby-2.5.3/bin:/Users/igeek/.rvm/gems/ruby-2.5.3@global/bin:/Users/igeek/.rvm/rubies/ruby-2.5.3/bin::/Users/igeek/.rvm/bin

@yurikoles
Copy link

This issue is still here after upgrade to Catalina.

@127
Copy link

127 commented Jun 6, 2019

+1 rvm get branch /fix-sed-darwin helps

@clive-devops
Copy link
Author

clive-devops commented Jun 6, 2019

+1 rvm get branch /fix-sed-darwin helps

No it does not. This issue has nothing at all to do with sed, that has been proven, please let's not go down that path again.

@127
Copy link

127 commented Jun 6, 2019

No it does not. This issue has nothing at all to do with sed, that has been proven, please let's not go down that path again.

I don't give a damn what this issue is about, but checking out this branch helps to get rid of this trouble quickly without exploding universe.

@clive-devops
Copy link
Author

clive-devops commented Jun 6, 2019

No it does not. This issue has nothing at all to do with sed, that has been proven, please let's not go down that path again.

I don't give a damn what this issue is about, but checking out this branch helps to get rid of this trouble quickly without exploding universe.

No it does not get rid of this issue. If it fixes it for you, it's not this issue, it's a different one.

@trinitronx
Copy link
Contributor

trinitronx commented Jun 11, 2019

No it does not. This issue has nothing at all to do with sed, that has been proven, please let's not go down that path again.

I don't give a damn what this issue is about, but checking out this branch helps to get rid of this trouble quickly without exploding universe.

No it does not get rid of this issue. If it fixes it for you, it's not this issue, it's a different one.

Correct! This is a platform detection & CLI flag API incompatibility issue. The original symptom / error was:

sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

This is due to the fact that Mac OS is originally based on BSD, not GNU! As such, the macOS version of sed command line utility is based on the BSD version of the utility, which lacks the -r command line flag.

You can verify this is the case by issuing man sed on a Mac, which would give you these clues:

SED(1)                    BSD General Commands Manual                   SED(1)

NAME
     sed -- stream editor

SYNOPSIS
     sed [-Ealn] command [file ...]
     sed [-Ealn] [-e command] [-f command_file] [-i extension] [file ...]

[... SNIP ...]

AUTHORS
     Diomidis D. Spinellis <dds@FreeBSD.org>

Note the mention of BSD and FreeBSD.org domain in the email address of the tools' maintainer. Also note the lack of -r command line flag option.

The GNU version of the utility supports option -r / -E / --regexp-extended as evidenced by its' manual page.

@trinitronx
Copy link
Contributor

Building on my previous comment towards a potential solution...

TLDR;

We could try using sed -E for POSIX portability here to avoid most platform detection issues.

Ideally, all platforms and versions of sed could be detected and the appropriate command line flags could be used to avoid errors or undefined behavior.

Rationale / Problem Description

RVM is a command line utility that relies on a shell (bash, zsh, etc...), and a set of pre-installed binary command line utilities. There are slight differences in features and support for both shells and these utilities.

Due to the fact that shells and CLI utilities on various *BSD / *nix platforms will not support the same exact set of command line flags across all platforms, it becomes important to focus on commonly supported command line APIs. Thus, try to use the POSIX supported standards if you want to ensure cross-platform capability in your scripts.

Below are the manual pages for the macOS Mojave 10.14.5 version of sed (BSD variant), and the Ubuntu 18.04.2 LTS version of sed (GNU variant). Pay attention to the mention of POSIX standards, and differences in support for flags: -r, and -E.

MacOS / BSD

Note: Maybe some BSD variants, but not all... see STANDARDS section in man page excerpt below:

SED(1)                    BSD General Commands Manual                   SED(1)

NAME
     sed -- stream editor

SYNOPSIS
     sed [-Ealn] command [file ...]
     sed [-Ealn] [-e command] [-f command_file] [-i extension] [file ...]

DESCRIPTION
     The sed utility reads the specified files, or the standard input if no files are specified, modifying the input as specified by a list of
     commands.  The input is then written to the standard output.

     A single command may be specified as the first argument to sed.  Multiple commands may be specified by using the -e or -f options.  All
     commands are applied to the input in the order they are specified regardless of their origin.

     The following options are available:

     -E      Interpret regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE's).  The
             re_format(7) manual page fully describes both formats.

[...SNIP...]
STANDARDS
     The sed utility is expected to be a superset of the IEEE Std 1003.2 (``POSIX.2'') specification.

     The -E, -a and -i options are non-standard FreeBSD extensions and may not be available on other operating systems.

GNU / Linux

SED(1)                                                                 User Commands                                                                SED(1)

NAME
       sed - stream editor for filtering and transforming text

SYNOPSIS
       sed [OPTION]... {script-only-if-no-other-script} [input-file]...

DESCRIPTION
       Sed is a stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).  While
       in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the  input(s),  and  is  conse‐
       quently more efficient.  But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

[...SNIP...]

       --posix

              disable all GNU extensions.

       -E, -r, --regexp-extended

              use extended regular expressions in the script (for portability use POSIX -E).

[...SNIP...]

REGULAR EXPRESSIONS
       POSIX.2  BREs should be supported, but they aren't completely because of performance problems.  The \n sequence in a regular expression matches the
       newline character, and similarly for \a, \t, and other sequences.  The -E option switches to using extended regular  expressions  instead;  the  -E
       option has been supported for years by GNU sed, and is now included in POSIX.

@clive-devops
Copy link
Author

I feel that altering the sed behaviour is just (re)hiding the underlying bug that system detection is never executed in this one case - re-entering an rvm folder after having exited it.
There are other source paths (routes) through the code that could be impacted by the missing system detection in this case.
system detection is still run on OSX bash, just not on OSX zsh, in this particular case as referenced in the attached, above, Dockerfile which proves the exact nature of this bug.

@clive-devops
Copy link
Author

... I'm just worried that another issue related to this will resurface, if anyone's wondering why i'm harping on about this. This issue has had severe impact for my team. // out

@trinitronx
Copy link
Contributor

trinitronx commented Jun 11, 2019

Proposed fix in PR #4711 to use POSIX.2 -E flag.

I'm guessing this fixes on most POSIX platforms, and it "works for me" ™️ on the following that I tested:

  • Ubuntu 18.04.2 LTS / sed version: sed (GNU sed) 4.4 (package: sed_4.4-2_amd64.deb)
  • macOS Mojave 10.14.5 / sed version: ?? (>= version in FreeBSD 2005, which supports -E)

Note that this may break backwards compatibility for older versions of Darwin, but it's apparently already broken if they did not support -E anyway because the test for Darwin conflates sed version too closely with OS version.

@trinitronx
Copy link
Contributor

trinitronx commented Jun 11, 2019

I feel that altering the sed behaviour is just (re)hiding the underlying bug that system detection is never executed in this one case - re-entering an rvm folder after having exited it.

It's already an arguably a loose assumption that OSX / platform version accurately reflects a version of sed installed. This will work in most cases, but it's never going to be 100% accurate. Unfortunately, the *BSD versions of sed don't even provide a way to detect their version. We'd have to resort to some kind of janky CLI sed -h help output flag support detection which could potentially cause other breakages. Not sure what RVM maintainers think is best here... 🤷‍♂ 😉

If we can rely on most modern shell + sed core util combinations including POSIX ERE support, then that would simplify the permutations for cross-platform compatibility here.

There are other source paths (routes) through the code that could be impacted by the missing system detection in this case.

Yeah, you're probably right 😉

Not sure where else it might crop up, but in this particular case as mentioned above, the test doesn't really check for the exact thing it needs to check for, sed version or -r vs -E support, just overarching platform which is loosely coupled to sed version. Probably best to just make that assumption and deal with platform changes as the come and go, but ideally rvm could detect some kind of standard set of commands and flags like with POSIX. Yet, then we still deal with versions of the standard over time 😄 🤦‍♂

C'est la vie 🤷‍♂

system detection is still run on OSX bash, just not on OSX zsh, in this particular case as referenced in the attached, above, Dockerfile which proves the exact nature of this bug.

I was able to reproduce with rvm 1.29.7-next (master) using bash on MacOS Mojave 10.14.5. So as it appears, this bug affects both bash and zsh when changing directory that rvm detects it needs to run and manage ruby version inside (e.g.: .ruby-version, .ruby-gemset, .rvmrc)

@chatwyn
Copy link

chatwyn commented Jan 20, 2020

+1 seeing the exact same issue. You can see how just cding into a folder with a .ruby-version file changes $PATH, and it stays broken even when I cd back to ~:

~ $ echo $PATH
/Users/igeek/.rvm/gems/ruby-2.5.3/bin:/Users/igeek/.rvm/gems/ruby-2.5.3@global/bin:/Users/igeek/.rvm/rubies/ruby-2.5.3/bin:/usr/local/sbin:/Applications/Sketch.app/Contents/Resources/sketchtool/bin/:/Users/igeek/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/opt/X11/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin
~ $ cd Projects/Siteswap  
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
(eval):1: command not found: cat
(eval):1: command not found: cat
~/Projects/Siteswap $ echo $PATH
/Users/igeek/.rvm/gems/ruby-2.5.3/bin:/Users/igeek/.rvm/gems/ruby-2.5.3@global/bin:/Users/igeek/.rvm/rubies/ruby-2.5.3/bin:/Users/igeek/.rvm/bin:
~/Projects/Siteswap $ cd                  
(eval):1: command not found: cat
(eval):1: command not found: cat
~ $ echo $PATH
/Users/igeek/.rvm/gems/ruby-2.5.3/bin:/Users/igeek/.rvm/gems/ruby-2.5.3@global/bin:/Users/igeek/.rvm/rubies/ruby-2.5.3/bin::/Users/igeek/.rvm/bin

I have same issue

@apkagh
Copy link

apkagh commented Feb 27, 2020

I need a help to fix this issue please : RVM can not be run with set -o posix, please turn it off and try again

I'm using Catalina

@trinitronx
Copy link
Contributor

@chatwyn , @apkagh This should be fixed as of #4711 What version of RVM are you using? Can you try:

rvm get head

Also another workaround was mentioned here, if for some reason you need to stay on an older version of RVM: remove the .ruby-version file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.