[Fix] sed: illegal option — r

The Error “sed: illegal option — r”, is an error that is invoked when you are working on Visual Studio Code and have recently updated your Visual Studio Code application on your system.

Given below is the snippet of the error you might get:

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

This error “sed: illegal option — r” is seen because of the latest update in Visual Studio Code which made some changes to the ‘sed – r’ function.

This issue is from the Visual Studio Code team itself and we can’t do much from our side except to wait for the VS Code team to fix the error.

There are some temporary workarounds to fix the error which are discussed below.

To fix the error, “sed: illegal option — r”, set HISTCONTROL in your /.bashrc to either erasedups, ignoreboth, or ignoredups and use the GNU sed, in place of the macOS (BSD) sed by using command ‘brew install gnu-sed –with-default-names’ and error would be fixed.

This issue is from the Visual Studio Code team itself and we can’t do much from our side except to wait for the VS Code team to fix the error. As per VS Code team, fixed version v1.71.1 would be released soon.

The -r option forces sed to perform an expanded regular expression syntax. The following input contained in single quotation marks (such as ‘) defines the “substitution” or find and replace function.

The last term of a sed command defines the file object that will be subjected to the replacement function.

Steps to fix the error “sed: illegal option — r” in VS Code:

Option 1: set HISTCONTROL in your /.bashrc

On OSX Catalina, sed -r is inoperable; you will receive errors for each command in the integrated terminal.

To get around this, set HISTCONTROL in your /.bashrc to either erasedups, ignoreboth, or ignoredups.

Option 2: Use GNU sed rather macOS (BSD)

The GNU sed should be used in place of the macOS (BSD) sed as a workaround.

gnu-sed to be installed via homebrew you will have to look at the below mentioned code to know how to do so:

brew install gnu-sed --with-default-names

Option 3: Downgrade VS Code version to v1.70

If nothing works for you, downgrade the VS code to the stable version v1.70 to fix the error and error sed: illegal option — r would be fixed.

This is problem is from the visual studio code team and we will have to wait for the team to fix the error in their next update.

This should help you fix the error, “sed: illegal option — r”.

Conclusion

To fix the error, “sed: illegal option — r” you will have to set HISTCONTROL in your /.bashrc to either erasedups, ignoreboth, or ignoredups.

The second option is that the GNU sed should be used in place of the macOS (BSD) sed as a workaround.

This is problem is from the visual studio code team and we will have to wait for the team to fix the error in their next update.