#!/bin/sh
emoji="U1f300-U1f5ffU1f900-U1f9ffU1f600-U1f64fU1f680-U1f6ffU2600-U26ffU2700-U27bfU1f1e6-U1f1ffU1f191-U1f251U1f004U1f0cfU1f170-U1f171U1f17e-U1f17fU1f18eU3030U2b50U2b55U2934-U2935U2b05-U2b07U2b1b-U2b1cU3297U3299U303dU00a9U00aeU2122U23f3U24c2U23e9-U23efU25b6U23f8-U23fa"
sample="This ๐ is โญ a ๐ข line ๐คฎ of ๐ emoji โ"
echo $sample
echo $sample | LC_ALL=UTF-8 sed -e "s/[$(printf $emoji)]//g"
The preceding script can obtain normal execution results on other Linux operating systems (such as centos). However, if the script is executed on OpenWRT, an error message is displayed sed: bad regex Invalid character range or the correct result cannot be obtained after execution. Attempts were made to change the sed version to 4.8 but the problem persisted. Is this bash or is the system environment incomplete?
- Attempts were made to change the sed version to 4.8 but the problem persisted
- emoji="U1f300-U1f5ff" Trying to shorten emoji also works on centos, not openwrt
2
Answers
If it is a system shell environment problem, but the following script can get normal results
May not be the answer but your quoting’s wrong, shebang is wrong, use of printf is wrong, use of echo instead of printf is wrong, locale is wrong, and you have a useless subshell calling
printf
so let’s clean up all of that and then see if you still have a problem. Try this: