Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'sed: illegal option -- r usage' error in Visual Studio Code

I just updated my Visual Studio application (now 1.71.0 (Universal)) on my Mac (High Sierra), and I noticed that when I start up my terminal in VSCode, that I get this message with every command that I run:

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

I think this has something to do with me updating VS Code, but I don't know why or how to fix it. Has anyone run into this before?

like image 372
elo Avatar asked Dec 05 '25 13:12

elo


2 Answers

Straightforward solution

Please, see the following references:

  • GitHub issue. [MacOs][Bug][Terminal] `sed: illegal option -- r` before executing commands · Issue #159864 · microsoft/vscode.
  • GitHub pull request. [main] Remove reliance on sed -r by Tyriar · Pull Request #160209 · microsoft/vscode.
  • GitHub pull request. [release/1.71] Remove reliance on sed -r by Tyriar · Pull Request #160210 · microsoft/vscode.

The solution is:

  1. To wait for a next Visual Studio Code release with the resolved issue.
  2. To upgrade to the release.

As per the GitHub issue comment:

Tyriar commented 2022-09-12T12:54:25Z

The fix for this is coming in 1.71.2, not sure on the release date currently.

Available release: 1.71.2

  • Release. Release August 2022 Recovery 2 · microsoft/vscode.
  • Tag. microsoft/vscode at 1.71.2.

Workaround solution #1

Please, see the GitHub issue: sed -r shell integration error on OSX · Issue #159946 · microsoft/vscode · GitHub.

Please, note the workaround-related comment:

Tyriar commented 2022-09-02T19:31:19Z

See comments in e55863c

sed -r doesn't work on OSX Catalina, I get an error at each command in the integrated terminal

Workaround for anyone hitting this is to set HISTCONTROL to one of erasedups, ignoreboth, ignoredups in your ~/.bashrc.

Workaround solution #2

The solution is to override («replace») the macOS (BSD) sed with the GNU sed.

For example, please, refer:

  • Question. How do I fix "sed: illegal option -- r" in macOS Sierra Android build? - Stack Overflow.

    • Answer.
  • Question. macos - How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported - Stack Overflow.

    • Answer.
like image 200
Sergey Vyacheslavovich Brunov Avatar answered Dec 07 '25 12:12

Sergey Vyacheslavovich Brunov


This may not be the most technically savvy solution, but I did this:

  1. Install gsed:

    brew install gnu-sed
    
  2. Make a symbolic link to gsed:

    cd /usr/local/bin
    ln -s gsed sed
    

When VSCode fixes the issue, I will delete the symbolic link, and uninstall gsed.

like image 31
doc07b5 Avatar answered Dec 07 '25 11:12

doc07b5