0

My Code is

special_chars='[=!=][=@=][=#=][=$=][=%=][=&=]'
PASS="e@0cc3auZeeSio&G"

PASS2="${PASS//[${special_chars}]/}"

I want PASS2 to have all the characters in PASS - special characters. This works fine, but there is shell check error on this.

PASS2="${PASS//[${special_chars}]/}"
             ^-- SC2039: In POSIX sh, string replacement is undefined.

I tried doing

PASS2=$(printf '%s' "$PASS2" | PASS//["${special_chars}"]/)

And

PASS2=$(printf '%s' "$PASS" | PASS//["${special_chars}"]/)

These does not work functionally.

Jens
  • 69,818
  • 15
  • 125
  • 179
  • Shellcheck is trying to tell you that the `//` construct in parameter expansion is not valid POSIX (it's a bashism). It is also not clear, what the special_chars shall do. Please tell us what PASS2 should be after the transformation. Do you want each of the characters !@$%& removed? – Jens Apr 09 '20 at 14:51

1 Answers1

0

This script passes shellcheck:

#!/bin/sh

special='!@#$%&'
PASS="e@0cc3auZeeSio&G"
PASS2=$(printf %s "$PASS" | tr -d "$special")
echo "$PASS2"
Jens
  • 69,818
  • 15
  • 125
  • 179