Post History
It is not the most elegant solution, but you may be able to use the string escape function of fish, as in: echo abc | sed -E (string escape 's/b+/X/') This would still escape the special charac...
Answer
#4: Post edited
- It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in:
- ```lang-shell
- echo abc | sed -E (string escape 's/b+/X/')
- ```
- This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped.
- So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).
- **Note** that the `+` metacharacter is [extended regular expression syntax](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended), which `sed` doesn't understand unless invoked with the `-E` option. When called "bare", it uses basic regular expressions, where the "one or more" would need to be expressed explicitly using range indicators, so you would need to write
```- echo abc | sed (string escape 's/b\{1,\}/X/')
- ```
where the `\` are now an actual part of the RegEx and therefore indispensable.
- It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in:
- ```lang-shell
- echo abc | sed -E (string escape 's/b+/X/')
- ```
- This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped.
- So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).
- **Note** that the `+` metacharacter is [extended regular expression syntax](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended), which `sed` doesn't understand unless invoked with the `-E` option. When called "bare", it uses basic regular expressions, where the "one or more" would need to be expressed explicitly using range indicators, so you would need to write
- ```lang-shell
- echo abc | sed (string escape 's/b\{1,\}/X/')
- ```
- where the `\` are now an actual part of the RegEx and therefore indispensable.
- **Update:** A comment by @Quasímodo notified me that the [GNU extension of BRE](https://www.gnu.org/software/sed/manual/sed.html#BRE-syntax) as used by GNU `sed` actually _does_ implement the `+` quantifier, but - similar to `{` and `}` - it must be given its special meaning by preceding it with a `\`. So in this case _the `\` is an integral part of the RegEx and must be literally passed to `sed` in the form `b\+`_ if you don't want to invoke it with `-E` to make use of ERE.
#3: Post edited
- It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in:
- ```lang-shell
- echo abc | sed -E (string escape 's/b+/X/')
- ```
- This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped.
- So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).
- **Note** that the `+` metacharacter is [extended regular expression syntax](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended), which `sed` doesn't understand unless invoked with the `-E` option. When called "bare", it uses basic regular expressions, where the "one or more" would need to be expressed explicitly using range indicators, so you would need to write
- ```
echo abc | sed (string escape 's/b\{1[](),\}/X/')- ```
- where the `\` are now an actual part of the RegEx and therefore indispensable.
- It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in:
- ```lang-shell
- echo abc | sed -E (string escape 's/b+/X/')
- ```
- This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped.
- So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).
- **Note** that the `+` metacharacter is [extended regular expression syntax](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended), which `sed` doesn't understand unless invoked with the `-E` option. When called "bare", it uses basic regular expressions, where the "one or more" would need to be expressed explicitly using range indicators, so you would need to write
- ```
- echo abc | sed (string escape 's/b\{1,\}/X/')
- ```
- where the `\` are now an actual part of the RegEx and therefore indispensable.
#2: Post edited
- It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in:
- ```lang-shell
echo abc | sed (string escape 's/b+/X/')- ```
- This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped.
So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).
- It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in:
- ```lang-shell
- echo abc | sed -E (string escape 's/b+/X/')
- ```
- This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped.
- So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).
- **Note** that the `+` metacharacter is [extended regular expression syntax](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended), which `sed` doesn't understand unless invoked with the `-E` option. When called "bare", it uses basic regular expressions, where the "one or more" would need to be expressed explicitly using range indicators, so you would need to write
- ```
- echo abc | sed (string escape 's/b\{1[](),\}/X/')
- ```
- where the `\` are now an actual part of the RegEx and therefore indispensable.
#1: Initial revision
It is not the most elegant solution, but you may be able to use the [`string escape`](https://fishshell.com/docs/current/cmds/string-escape.html) function of `fish`, as in: ```lang-shell echo abc | sed (string escape 's/b+/X/') ``` This would still escape the special characters, but in a "hidden" way - the user-visible RegEx is not cluttered with backslashes and the `sed` command sees the result of the command substitution, which is properly escaped. So far, I don't know of any shell that has a feature to turn off interpretation of special characters (if anyone knows, it would likely be Stéphane Chazelas over at U&L SE).