我的代码是
special_chars='[=!=][=@=][=#=][=$=][=%=][=&=]'
PASS="e@0cc3auZeeSio&G"
PASS2="${PASS//[${special_chars}]/}"
我希望 PASS2 包含 PASS 中的所有字符 - 特殊字符。这工作正常,但有外壳检查错误。
PASS2="${PASS//[${special_chars}]/}"
^-- SC2039: In POSIX sh, string replacement is undefined.
我试着做
PASS2=$(printf '%s' "$PASS2" | PASS//["${special_chars}"]/)
和
PASS2=$(printf '%s' "$PASS" | PASS//["${special_chars}"]/)
这些在功能上不起作用。